So, I'm trying to dynamically create ListElements in a ListModel . This works fine until I try to write some content in the loadable ListElements element dynamically.
I tried to create my own file with the ListElement inside and the hour as a property, but then the model had an error saying that ListElements could not be nested.
Error starting code below:
Cannot assign non-existent hour property
How can i solve this?
Code:
import QtQuick 2.0 ListModel { id: listModel Component.onCompleted: { for (var i = 0; i < 24; i++) { var object = createListElement(listModel) } } function createListElement(parent) { var object = Qt.createQmlObject('import QtQuick 2.0; ListElement { hour: "01" }', parent); return object; } }
EDIT: Change the line of code in the function to:
var object = Qt.createQmlObject('import QtQuick 2.0; ListElement { property string hour: "23" }', parent);
Now I get no errors, but the items are still not showing in the list.
DECISION:
import QtQuick 2.0 ListModel { id: listModel Component.onCompleted: { for (var i = 0; i < 24; i++) { append( { hour: i.toString() } ) } } }
source share