How to access ListModel element members in ListView's delegate via Loader
Unsolved
QML and Qt Quick
-
ListModel { id: coolModel ListElement { name: "Bill Smith" } ListElement { name: "John Brown" } }
Component { id: testTest Text { text: name } }
ListView { anchors.fill: parent boundsBehavior: Flickable.StopAtBounds clip: true model: coolModel delegate: Loader { height: childrenRect.height width: parent.width sourceComponent: testTest } }
How to access
name
in ComponenttestTest
? Looks like the ListView's context (the variables from my ListModel) is not passed through the Loader.ReferenceError: name is not defined
-
Try:
ListView { anchors.fill: parent boundsBehavior: Flickable.StopAtBounds clip: true model: coolModel delegate: Loader { sourceComponent: Text{ text: model.name } } }
or maybe you want in testTest:
Item { property alias text: some_text.text Text { id: some_text text: "a name" } }