QML TreeView from C++ QAbstractItemModel
-
Hi,
I have a custom C++ QAbstractItemModel that is working nicely when using Qt Widget QTreeView. Now, I want to use the C++ model directly in QML.
I got inspired by the following article:
http://www.codeproject.com/Articles/632795/QML-TreeModel-and-TreeViewIn particular, creating a recursive delegate seems the way to go. My current QML is:
@ Component
{
id: sceneNodeDelegateRecColumn { id: columnRec Text { id: text text: model.modelData // use qualified names for clarity sake color: "white" } Repeater { id: repeaterRec model: model.getChildren() // <<== TypeError: Cannot call method 'getChildren' of undefined delegate: sceneNodeDelegateRec } }
}
ListView
{
id: sceneGraphView
anchors.fill: parent
model: sceneGraphModel
delegate: sceneNodeDelegateRec
}@So my questions are:
1) How can I reference "parent model" in the recursive delegate's Repeater;
2) How can I pass to Repeater.model the children of parent model doing something like parentModel.getChildren()?Thanks for any help.
Best regards. -
Any idea? Anyone?
Thanks in advance.
Best regards. -
I do not know, but you definitely can Vote for "this bug":https://bugreports.qt-project.org/browse/QTBUG-29886?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-236957