Access object property in JS
I've created a couple of my own objects, container and item
Items are movable and periodically I check for some condition, let's say fot objects intersection.
If required event occurs, the object emits a signal:
Code:
class Container : public QQuickItem {
public:
void checkIntersection() {
foreach
(QObject *child, childItems
()) { if (MyObject *obj = dynamic_cast<MyObject*>(child)) {
...
if(intersected(obj,other_obj)) emit intersect(other_obj);
}
}
}
bool intersected(MyObject * obj,MyObject * other) {
...
return true;
}
signals:
intersect(MyObject * other);
}
class MyObject : public QQuickItem {
...
}
and QML structure for better understanding:
Code:
Container {
MyObject {
id: object1
...
onIntersect: {
if(other.id === "object2") { // error, id is undefined
doSomething();
}
}
}
MyObject {
id: object2
...
}
}
As you can see, when I trying to get object property (id) I get error. I can read some properties, width or height for example, but id is inaccesible.
What I do wrong?
Re: Access object property in JS
I think you can do
i.e. using the id like a reference to the object
Another option would be to set the "objectName" property and compare with that.
Cheers,
_