[Solved]Accessing nested ListModel in a separate file issue...
-
Hello,
I am new to Qt, so please bear with me if I am posting a silly question.
I have a nested ListModel in a separate file as follows (I just put one element in there for brevity):
@import QtQuick 1.0
ListModel {
id: topModel
ListElement {
mainScreen: [
ListElement {
title: "Settings"
}
]
}
}
@
I have a separate qml file that has the ListView to access the nested "mainScreen" list as follows:@ListView {
id: list2
y: 10; width: 100; height: 100
focus: true
model: topModel.get(0).mainScreen
delegate: MainScreenDelegate {}
}
@
When I run it, it gives me the following error and does not show anything :ReferenceError: Can't find variable: topModel
Please help me identify what I do it wrong.
Thanks.
-
I finally found how to make the code look correct in the post.
Your help on the question will be really appreciated.
-
I think nesting a ListModel as shown in your sample is not supported.
You could however, store a set of models in a property:
@
...
ListModel {
id: modelA
ListElement { title: "Title A1" }
ListElement { title: "Title A2" }
}
ListModel {
id: modelB
ListElement { title: "Title B1" }
ListElement { title: "Title B2" }
}
property var models: [
modelA, modelB
]
...
ListView {
...
model: models[0]
...
}
@See also: "ListModel":http://qt-project.org/doc/qt-5.1/qtqml/qml-qtqml-models2-listelement.html, "ListElement":http://qt-project.org/doc/qt-5.1/qtqml/qml-qtqml-models2-listelement.html, "Variant":http://qt-project.org/doc/qt-5.1/qtqml/qml-variant.html
-
Thanks for the reply. Appreciate it.