[Qt-qml] Dummy model for QList<QObject*> model
michael.brasser at nokia.com
michael.brasser at nokia.com
Thu Sep 16 05:44:24 CEST 2010
On 15/09/2010, at 5:33 PM, ext Cornelius Hald wrote:
On Wed, 2010-09-15 at 05:53 +0200, michael.brasser at nokia.com<mailto:michael.brasser at nokia.com> wrote:
On 15/09/2010, at 12:32 AM, ext Cornelius Hald wrote:
On Tue, 2010-09-14 at 16:10 +0200, Stephen Kelly wrote:
Cornelius Hald wrote:
Thanks! qmlRegisterType() helped with my own model (derived from
QAbstractListModel). With QObjectListModel I'm still having a problem,
because I don't understand how the roles are defined. From looking at
the code and the comments it looks like only one role with the name
"object" is defined. But then, how should I use it in QML?
Define Q_PROPERTIES and access them on the object.
delegate : Text { text: model.object.someProp; height : 20 }
I wrote something similar before but used the term 'data' instead of
'object', so I used model.data.someProp.
http://steveire.wordpress.com/2010/02/19/qml-with-akonadi-or-how-to-use-
your-existing-model-view-design-with-qml/
Thanks Steve, but then I'm having the same problem as with
QList<QObject*> models. In both cases they are accessed in a different
way compared with QML ListModels.
Maybe we could write a generic wrapper like, for example, ListModel<T>
that would expose all properties of the containing type T as roles. Not
sure if that is possible, though. It's just a couple of days since I'm
in Qt land :)
One of the reasons I haven't done this for QObjectListModel is because it is not very pretty/fast with our current model API -- the model would have to monitor all changes to the object's properties, and emit dataChanged appropriately.
With object, the binding below is automatically updated when the object's name property changes (thanks to NOTIFY):
Text { text: model.object.name<http://model.object.name> }
In the binding below, the model needs to know when the name property of the object changes, so it can emit dataChanged, causing the binding to update:
Text { text: model.name<http://model.name> }
Thanks for the explanation. It's much clearer now. Just to make sure I
did completely understand the issue: The performance issue is also valid
for custom models based on QAbstractListModel, right? There the
situation is the same that whenever a property of a contained object
changes, the model needs to be informed and the model then informs the
view?
Yes -- if the model is wrapping non-static QObjects, and the model's roles mirror the properties of the object, then the issues are the same.
Regards,
Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20100916/0d54e66c/attachment.html
More information about the Qt-qml
mailing list