[SOLVED] Populate a QML ListView with a custom C++ model
-
Hi,
I have a custom Model representing a tree based on this example:
http://qt-project.org/doc/qt-5/qtwidgets-itemviews-simpletreemodel-example.htmlMy internal model is correctly populated and I can manually output it to console to check that it works perfectly.
In the QML, I do something like:
@ ListView
{
id: sceneGraphView
anchors.fill: parentmodel: sceneGraphModel delegate: sceneNodeDelegate
}@
Unfortunately, I only get the first element of my model. Is this the correct way to populate a ListView?
Also, the model's methods called when I launch the application are:
@rowCount
roleNames
index
rowCount
columnCount
data @Thanks for any help.
-
Hi,
Are you calling "beginInsertRows":https://qt-project.org/doc/qt-5.1/qtcore/qabstractitemmodel.html#beginInsertRows and "endInsertRows":https://qt-project.org/doc/qt-5.1/qtcore/qabstractitemmodel.html#endInsertRows when populating the list ?
See "this":https://qt-project.org/doc/qt-5.1/qtquick/qtquick-modelviewsdata-cppmodels.html example for how to use C++ model in QML -
Thanks for your answer.
The model is already populated when the view access it the first time calling rowCount.
My main concern is about the C++ model members called from the QML ListView. I am not sure it is correct and sufficient.
Best regards.
-
Ok, it seems that the QML View I use is not appropriate for that. When testing with a QTreeView, it worked immediately. What QML view should I use then to display a Tree in QML? it seems that none are present for the moment.
Thanks for any help.
-
Hi,
Currently there's no of Treeview for QML. But there are some work around's
For eg. See "this":http://qt-project.org/forums/viewthread/30521/#136940 -
Ok, I see. Thanks a lot for your help!