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:
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 {
...
}
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 {
...
}
To copy to clipboard, switch view to plain text mode
and QML structure for better understanding:
Container {
MyObject {
id: object1
...
onIntersect: {
if(other.id === "object2") { // error, id is undefined
doSomething();
}
}
}
MyObject {
id: object2
...
}
}
Container {
MyObject {
id: object1
...
onIntersect: {
if(other.id === "object2") { // error, id is undefined
doSomething();
}
}
}
MyObject {
id: object2
...
}
}
To copy to clipboard, switch view to plain text mode
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?
Bookmarks