Qt nested ListView or can I use TreeView
<p>I am working on a project where I want to have a GUI like this:
<a href="https://i.stack.imgur.com/ZGfps.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ZGfps.png" alt="tree like GUI"></a></p>

<p>I have a list of my class (the blue one), and it has a list of the green class, so far my C++ structure is good, and I can get data from C++ in qml and vice versa, but I am not sure how to make the GUI work correct, I have triede with nested ListViews, but it seems like that I have no access to the outer ListView model from the inner ListView..</p>

<p>I am pretty new to qml, and yesterday I found the TreeView, but to me it looks like that is only usefull if you have a table structure. Is there some qml that I dont know about that can help me with this?</p>

<p>I have tried this with nested ListViews, the idea beeing that the inner ListView get a object of the green class as model.</p>

<pre><code>ListView {
id: userView
anchors.fill: parent
model: myModel
delegate: Rectangle {
    width: 900
    height: 200
    Column {
        id: col
        anchors.left: parent.left
        anchors.right: parent.right

        Item { height: 10 }
        Text {
            text: model.type + " " + model.name
        }
        Row {
            spacing: 8
            Button {
                id: addLevel
                width: 80
                text: "Add Level"
                enabled: setVisible
                elevation: 1
                backgroundColor: Theme.primaryColor
                onClicked: {
                    myModel.insertLevel(index)
                }
            }
            Button {
                id: delTariff
                width: 80
                text: "Delete User"
                enabled: setVisible
                elevation: 1
                backgroundColor: Theme.primaryColor
                onClicked: {
                    myModel.removeTariff(index)
                }
            }
            Button {
                id: delLevel
                width: 80
                text: "Delete Level"
                enabled: setVisible
                elevation: 1
                backgroundColor: Theme.primaryColor
                onClicked: {
                    myModel.removeLevel(index, 0)
                }
            }
        }
        Text {
            text: model.levels
        }
        Row {
            spacing: 8
            Repeater {
                model: myModel.levelStructModel(userView.index)
                Rectangle {
                    height: 30
                    width: 30
                    color: "blue"
                }
            }
        }
    }
}
</code></pre>

<p>I also have problem with the program craching after adding or deleting stuff, I tried add the <code>QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership)</code> in the contructor of myModel, but without any luck.</p>