[Qt-qml] dynamically updatable model in QML ListView
vineeth
nvineeth at gmail.com
Mon May 23 12:01:32 CEST 2011
Thanks a lot for the link on qabstractlistmodel , I could find the required
example here :
http://doc.trolltech.com/4.7.1/declarative-modelviews-abstractitemmodel.html
Also this is extremely efficient than earlier, where I used to repeatedly
reassign the model variable, every-time the data had changed.
--vineeth
On Fri, May 20, 2011 at 4:38 PM, Pelle Johnsen <pelle.johnsen at gmail.com>wrote:
> If your model is C++ based QAbstractListModel is the way to go.
>
> You need to override the rowCount and data methods and then use
> begin/endInsertRows when adding new items. This will inform ListView about
> those changes and it will then update the appropriate delegates.
>
> http://doc.qt.nokia.com/latest/qabstractlistmodel.html
>
> <http://doc.qt.nokia.com/latest/qabstractlistmodel.html> -Pelle
>
> On Fri, May 20, 2011 at 12:26 PM, vineeth <nvineeth at gmail.com> wrote:
>
>>
>> I could get this working using : declView->rootContext()->
>> setContextProperty(...) to update the model variable used in QML
>> ListBiew, but I think this involves unnecessary computation.
>> A more optimal way will be to get a reference to the model of the ListView
>> and call append on it.
>> There is a example of this in :
>> C:\QtSDK\Examples\4.7\declarative\modelviews\listview\dynamiclist\qml\ and I
>> need to do the same using C++ backend.
>> Thanks all for the kind reply.
>> --vineeth
>>
>>
>>
>> On Fri, May 20, 2011 at 3:18 PM, Pelle Johnsen <pelle.johnsen at gmail.com>wrote:
>>
>>> If using ListModel you don't need to reassign the whole model (which is
>>> bad as it requires ListView to recreate or at least reinitialize all
>>> delegates).
>>>
>>> ListModel has methods for updating the model: append, insert, move,
>>> remove, clear. I'm guessing it's using the item views mechanism under the
>>> hood to inform ListView of the changes.
>>>
>>> -Pelle
>>>
>>>
>>> On Fri, May 20, 2011 at 11:26 AM, Thomas Ganshorn <
>>> mailings at novaimages.de> wrote:
>>>
>>>> i read once that you have to reassign the modell to the listview.
>>>>
>>>> Not quite good implementation but there seems to be no other solution
>>>> unless you want to write your own qaim model (wich is something i really
>>>> hate and would always avoid if possible)
>>>>
>>>
>>
>> _______________________________________________
>> Qt-qml mailing list
>> Qt-qml at qt.nokia.com
>> http://lists.qt.nokia.com/mailman/listinfo/qt-qml
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20110523/a4954e9f/attachment.html
More information about the Qt-qml
mailing list