emitting multiple signals at once from c++ to qml
-
Hello,
I have a list of my onw QObjects in C++QList<QObject *>
This list is exposed to QML by a wrapper class
qmlRegisterSingletonType<ListManager> ("foo", 1, 0, "Lists", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { Q_UNUSED(engine) Q_UNUSED(scriptEngine) return new ListManager; });
In QML I iterate over that list to dynamically create a bunch of objects
... for(var i=0; i < objects.length; i++) { var myCppObject = objects[i]; var object = Qt.createQmlObject('MyQMLObject {}', parent); object.property = Qt.binding(function() {return myCppObject.property; }); ...
As you can see I am using Qt.binding() to bind a property from the Cpp Object to the QML Object. This property is defined like this:
// myobject.cpp Q_PROPERTY(int property READ property NOTIFY propertyChanged) signals: void propertyChanged(int newProperty);
Now when I change a bunch of objects in a loop in C++ I get the following behavior (in pseudo code):
//in cpp emit propertyChanged(1); //for object 1 emit propertyChanged(2); //for object 2 emit propertyChanged(3); //for object 3 // in qml onPropertyChanged 3 // for object 3 onPropertyChanged 3 // for object 1 onPropertyChanged 3 // for object 2
What am I missing?
Thank you,
erikm -
Hello,
I have a list of my onw QObjects in C++QList<QObject *>
This list is exposed to QML by a wrapper class
qmlRegisterSingletonType<ListManager> ("foo", 1, 0, "Lists", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { Q_UNUSED(engine) Q_UNUSED(scriptEngine) return new ListManager; });
In QML I iterate over that list to dynamically create a bunch of objects
... for(var i=0; i < objects.length; i++) { var myCppObject = objects[i]; var object = Qt.createQmlObject('MyQMLObject {}', parent); object.property = Qt.binding(function() {return myCppObject.property; }); ...
As you can see I am using Qt.binding() to bind a property from the Cpp Object to the QML Object. This property is defined like this:
// myobject.cpp Q_PROPERTY(int property READ property NOTIFY propertyChanged) signals: void propertyChanged(int newProperty);
Now when I change a bunch of objects in a loop in C++ I get the following behavior (in pseudo code):
//in cpp emit propertyChanged(1); //for object 1 emit propertyChanged(2); //for object 2 emit propertyChanged(3); //for object 3 // in qml onPropertyChanged 3 // for object 3 onPropertyChanged 3 // for object 1 onPropertyChanged 3 // for object 2
What am I missing?
Thank you,
erikmThis post is deleted!