List of custom object with Q_PROPERTYs as model?
-
Hi,
I have a vector of custom objects
vector<MyObject> myVector;
which expose their variables via Q_PROPERTY to qml:
class MyObject: public QObject { Q_OBJECT Q_PROPERTY(int prop1 READ prop1 WRITE setProp1 NOTIFY prop1Changed) Q_PROPERTY(int prop2 READ prop2 WRITE setProp2 NOTIFY prop2Changed) ...
I would like to make a model out of this vector, which I can use in a repeater. I know that it is possible to use
_eng->rootContext()->setContextProperty("myModel",QVariant::fromValue(myVector));
but according to the docu
Note: There is no way for the view to know that the contents of a QList has changed. If the QList changes, it is necessary to reset the model by calling QQmlContext::setContextProperty() again.
I would like to avoid always calling setContextProperty. Is it possible to make a model out of my vector which automatically updates the GUI?
Or do I understand the doc wrong: If I don't change the elements of the vector but the properties inside an element, would there be an update?
-
Hi,
I have a vector of custom objects
vector<MyObject> myVector;
which expose their variables via Q_PROPERTY to qml:
class MyObject: public QObject { Q_OBJECT Q_PROPERTY(int prop1 READ prop1 WRITE setProp1 NOTIFY prop1Changed) Q_PROPERTY(int prop2 READ prop2 WRITE setProp2 NOTIFY prop2Changed) ...
I would like to make a model out of this vector, which I can use in a repeater. I know that it is possible to use
_eng->rootContext()->setContextProperty("myModel",QVariant::fromValue(myVector));
but according to the docu
Note: There is no way for the view to know that the contents of a QList has changed. If the QList changes, it is necessary to reset the model by calling QQmlContext::setContextProperty() again.
I would like to avoid always calling setContextProperty. Is it possible to make a model out of my vector which automatically updates the GUI?
Or do I understand the doc wrong: If I don't change the elements of the vector but the properties inside an element, would there be an update?