[Development] QML and QAbstractListModel

Mark markg85 at gmail.com
Thu Jan 10 22:14:56 CET 2013


On Thu, Jan 10, 2013 at 8:06 PM, Charley Bay <charleyb123 at gmail.com> wrote:
> Alberto sayeth:
>>
>> > Hi all!
>> >    I'd like to make C++ models more usable from QML; in the net there
>> > are several blog posts illustrating how to achieve that, but IMHO it
>> > would be better if at least some of these handy features were in
>> > QAbstractListModel itself:
>> >
>> > - "count" property
>> > - "get(index)" invocable method, returning a QVariantMap mapping all the
>> > roles to their data for the specified index
>
>
> Alan respondeth:
>>
>> +1 from me, those would clearly make it more QML-friendly.
>>
>> > Also, though not very often requested, we could add:
>> > - "remove(index)" which just calls QAbstractItemModel::removeRow()
>> > - "QList<QVariant> items(const QString &role)", which returns the data
>> > for the role "role" for all items.
>>
>> I'm on the fence about adding those. Since they wouldn't be commonly
>> used, maybe it would be better to wait until there's time for a more
>> holistic 'models in QML' update (which likely means waiting a long
>> while, but eventually QML and QtQuick will need to deal with the issue
>> of full tree model support).
>>
>> > The implementation for the above is fairly trivial, so I wonder if
>> > there's some other reasons why it hasn't been done or if it's just that
>> > no one did and a patch is welcome.
>>
>> To my knowledge it's the latter. There's a lot of Qt API which could
>> be made more QML friendly, especially in this way (just adding
>> properties and convenience functions, for when a user subclass is
>> exposed to QML).
>
>
> Funny this should be posted -- I'm coding a "wrapper" for a bunch of
> app-specific QML/QAIM right now.
>
> I assume we are all referencing Chris' blog post from two years ago:
>
> http://cdumez.blogspot.com/2010/11/how-to-use-c-list-model-in-qml.html
>
> ...and BenoƮt's referencing blog from a year ago with some "extensions":
>
> http://bsauts-en.blogspot.com/2011/09/listmodel-in-c-exposed-to-qml.html
>
> ...and stuff like QML "read/write (role)" updates:
>
> http://qt-project.org/forums/viewthread/21787/
>
> ...and making a "model" a property of an item within another "model":
>
> http://qt-project.org/forums/viewthread/6906
>
> There's not tons of C++QAIM/QML blog posts out there, so please jump in if
> you know of others.

<snip>
Jumping in here.

I don't want to "advertise" my blog, but since you asked for others,
here is mine [1].  If i'm posting it's quite often about QML with some
C++ wrapper stuff. I should probably post more since i know a lot more
QML then you can see on my blog.

[1] http://kdeblog.mageprojects.com/



More information about the Development mailing list