Reputation: 1463
How can I append my dynamically created Qml Object to a ListModel?
I tried this, but it doesn`t work.
property ListModel projects
Component.onCompleted: {
var comp= Qt.createComponent("Project.qml");
var object = comp.createObject(parent,{});
projects.append(object);
}
Thanks.
Upvotes: 0
Views: 1559
Reputation: 633
ListModel append(), insert() and set() take a dictionary as their argument. So you will need to wrap the object returned by createObject() into a dictionary.
Also create an instance of the ListModel to assign to projects properties so that you can append to it.
property ListModel projects: ListModel {}
Component.onCompleted: {
var comp= Qt.createComponent("Project.qml");
var object = comp.createObject(parent, {});
projects.append({"name": object});
}
Upvotes: 1