Whenever I was creating a Q_PROPERTY for later use in Qml I always created a notify signal to tell qml that data changed and needs to be reevaluated.
Now having a Q_PROPERTY of the type QQmlListProperty<T> how can I signalize that an item has been modified, added or removed?
Is this even possible?
If you have a list there can't be a
propertyChanged()signal, because the object reference stored will remain the same.Within the list there won't be properties, so no signal is emitted.
You could instead use a descendent of
QAbstractListModelwhich is designed to handle this problem, by wrapping the methods to append, insert etc. in own methods, that then will emit adataChangedsignal that carries the information necessary to find the changes.Of course you could implement something similar yourself by wrapping a
QListin another object, that has a signal that will inform you of the data change. However this won't integrate that nicely with QML as a real model, for at least view will update automatically, when thedataChangedsignal is received, and they even only update what is necessary.Not so, if the
modelof theViewis changed directly, as might happen, if you manually callmodelChanged(). In this case, theViewwould miss the information about the changed parts, so it will just recreate itself completely.