C++ listmodel with section.property
-
Thanks for your answer.
maybe i was not clear.
i have a cpp model using QAbstractListModel and i use it in QML files and it works ok
BUT
i want to have the section attribute that ListView have in QML and i dont know how to implement it in the QAbstractListModel
do i need to implement the headerData method in the QAbstractListModel?? -
Just to clarify in QML
section.property holds the name of the property that is the basis of each section.If you look at the example in "QML Data Models":http://doc.qt.nokia.com/4.7-snapshot/qdeclarativemodels.html#qabstractitemmodel it shows that the roles in the c++ model is used in QML. In the example the roles are "type" and "size". So if you want to create a section base on "type" you would alter the QML example (in the link) to:
@ListView {
width: 200; height: 250
anchors.fill: parentmodel: myModel delegate: Text { text: "Animal: " + type + ", " + size } section.property: type
}@
Hope that is what you are looking for. The above snippet is untested of course
-
I have the same problem and i found solution - you should write
section.property: "modelData.<propertyName>"@ggeorge82 Thank you, this fixed my issue