[SOLVED] update an item of qabstractlistmodel
-
wrote on 13 Mar 2015, 10:50 last edited by samidarko
Hi,
I implemented qabstractlistmodel today following this documentation:
http://doc.qt.io/qt-5/qtquick-modelviewsdata-cppmodels.html- I don't get how to update one specific item of the list. I can access to the item by model index but I don't have any setter and I don't find any example, do anybody knows a doc explaining this?
More specifically, I can access in QML to my Animal object like this:
- model[index].size
- model[index].size = 5 // this what I want to do
- I usually use Class inheriting from QObject but I can't do that with qabstractlistmodel, is it still possible to set properties Q_PROPERTY in Animal?
Thanks by advance for your help
- I don't get how to update one specific item of the list. I can access to the item by model index but I don't have any setter and I don't find any example, do anybody knows a doc explaining this?
-
Hi,
I implemented qabstractlistmodel today following this documentation:
http://doc.qt.io/qt-5/qtquick-modelviewsdata-cppmodels.html- I don't get how to update one specific item of the list. I can access to the item by model index but I don't have any setter and I don't find any example, do anybody knows a doc explaining this?
More specifically, I can access in QML to my Animal object like this:
- model[index].size
- model[index].size = 5 // this what I want to do
- I usually use Class inheriting from QObject but I can't do that with qabstractlistmodel, is it still possible to set properties Q_PROPERTY in Animal?
Thanks by advance for your help
wrote on 13 Mar 2015, 14:20 last edited by@samidarko You could implement https://doc-snapshots.qt.io/qt5-5.4/qabstractitemmodel.html#setData or just change the value of your data and then just call the signal yourself.
- I don't get how to update one specific item of the list. I can access to the item by model index but I don't have any setter and I don't find any example, do anybody knows a doc explaining this?
-
@Buttink Thanks, next time I'll read the doc more thoroughly ;-)
For my second question, do you think it is possible?wrote on 13 Mar 2015, 16:42 last edited by@samidarko So for me, I use QObjects in my model with Q_PROPERTYs which means that If i change the same instance that the QmlEngine has then the notify signal will be fired for my property and Qml will reevaluate the binding. So for me I almost never check updates I only check when an Item is deleted or added to my model. Does that help?
-
Hi and welcome to devnet,
QabstractListModel is a QObject so you can derive from it like you want. Put the macro when using e.g. signals and slots and you should be good to go.
-
@samidarko So for me, I use QObjects in my model with Q_PROPERTYs which means that If i change the same instance that the QmlEngine has then the notify signal will be fired for my property and Qml will reevaluate the binding. So for me I almost never check updates I only check when an Item is deleted or added to my model. Does that help?
wrote on 15 Mar 2015, 01:31 last edited by@Buttink what is bothering me with qabstractlistmodel, are the items/rows contained in the list. Many times I pass this Item in a detail page and I find very practical to have a QObject. I was thinking of using this:
https://qt.gitorious.org/qt-labs/qml-object-model
but the last commit is 2011... -
Hi and welcome to devnet,
QabstractListModel is a QObject so you can derive from it like you want. Put the macro when using e.g. signals and slots and you should be good to go.
wrote on 15 Mar 2015, 01:59 last edited by@SGaist Thanks, that's interesting but I want to use Q_PROPERTY in the Item/row of the list e.g. Animal (cf. Qt doc example) which are not QObject cause, in my case, the rows are "links" and I use StackView to push a new view with the current item as an argument.
-
Ok, I understand your goal better
Just give it a run, it's not because it's old that it's outdated ;)
-
wrote on 16 Mar 2015, 03:51 last edited by
Finally I gave a shot to https://qt.gitorious.org/qt-labs/qml-object-model
It works fine, just needed to reimplement setRoleNames (deprecated in qt5)
Thanks again to the community :D
4/9