[Qt-qml] [Qt-interest] qml and real c++ application : QabstractItemModel ?
Gregory Schlomoff
gregory.schlomoff at gmail.com
Tue Dec 28 04:38:22 CET 2010
We use QML in a true life, complex application (a desktop email client
with the interface fully done in QML)
Over the course of the last few months, we tried a lot of different
setups, until we found what works best for us:
a. We have a few different data models (like Mail, Contact, Project,
etc...). Each model is stored in a sqlite table, and has a class to
represent it.
b. Each model class implements Qt's copy on write semantics, with
QSharedDataPointer. This makes it very easy to work with models and
pass them along, but it also mean that our models can't be QObjects,
and can't have Q_PROPERTIES, thus making it hard to work with them on
the QML side.
c. So for each Model, we have a corresponding ModelObject class that
exposes the data of the model through Q_PROPERTIES. For example, for
the Mail Model, we have the Mail and MailObject classes. MailObject is
created from a Mail instance, and allows to access the data from the
Mail through Q_PROPERTIES.
d. Internally, we only work QList of models. So all the mail in a
folder will be stored in a QList<Mail>, for example. This makes it
very easy for us to work with the data, copy it, etc... Then, to
expose data to QML, we use QObjectListModel
(http://qt.gitorious.org/qt-labs/qml-object-model/) that basically
makes QAbstractListModel out of a QList.
This setup may seem a little bit complicated, especially the fact that
for each model we actually have two classes (Mail and MailObject,
Contact and ContactObject, etc...), but thanks to some nice macros,
it's quite easy to maintain it. The fact that the models are fully
shared, copy-on-write classes that we can put in QLists or QHashes is
a huge win, in my opinion, and really worth the effort.
I think I'm going to write a blog post to give more details about this
setup, if anyone is interested.
(Also, if you want to try it out, you may sign-up for the beta:
http://betterinbox.com - will be ready in a couple of weeks :)
Cheers,
Greg
On Tue, Dec 28, 2010 at 5:56 AM, qt next <qtnext at gmail.com> wrote:
> thanks a lot for a true life example ;)
>
> 2010/12/27 Yuvraaj Kelkar <yuvraaj at gmail.com>
>>
>> > Hi,
>> >
>> > I am trying to create a new application that use qml for interface (to
>> > visualize and edit datas). I understand how to use qml with some simple
>> > model (list, ...) : but in the real life, is it better to use one
>> > complex
>> > QAbstractItemModel that acces all the data of my application (with
>> > complex
>> > tree ...) or to have a lot of qabstractitemmodel simpler (list, ...), or
>> > to
>> > not use at all qabstractItemModel ? is there any feedback from people
>> > that
>> > use now QML in the true life (not a simple contact list ,...) ?
>>
>> My code is a contact list in which each contact has a list of phone
>> numbers.
>> I started off with a tree view style approach by embedding a ListView
>> (numbers) inside the outer ListView's delegate Item.
>> This worked, but it was not pretty.
>>
>> I settled with two separate list views. When the user clicks on a
>> contact, the contact ListView modifies the model of the ContactDetails
>> ListView.
>> Then with some opacity magic, the ContactDetails view is shown and the
>> main contact list is hidden.
>>
>> Code is here:
>> http://code.google.com/p/qgvdial/source/browse/#svn%2Ftrunk%2Fqml
>> _______________________________________________
>> Qt-qml mailing list
>> Qt-qml at qt.nokia.com
>> http://lists.qt.nokia.com/mailman/listinfo/qt-qml
>
>
> _______________________________________________
> Qt-qml mailing list
> Qt-qml at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-qml
>
>
More information about the Qt-qml
mailing list