[Solved]How to Create ListModel in runtime
-
Tell me please how to create a ListModel in runtime and to keep it's handle
-
To create a model at runtime use a component and instantiate it:
http://doc.qt.nokia.com/4.7-snapshot/qdeclarativedynamicobjects.htmlThis may also work :
http://cdumez.blogspot.com/2010/11/heterogeneous-list-model-in-qml.html
Next,
use model.append() to add dynamic data to your model....you can call this from a javascript function..something like this:
//this is just pseudo code...@
myFunction()
{
var data = ["1","2","3","4","5","6","7","8"];
var i = 0;
for (i=0; i<data.length; i++){
model.append({"digit": data[i]}); //here digit is a role
}
}
@in your delegate, your data can now be accessed through the digit role.
@delegate:
Text {
color: "red"
text: digit + "index=" + " " +index
}@ -
Excuse me that i has written not clearly.
I meant i need to create the ListModel object itself.ex:
By pressing the Button1 the ListModel is created,
By pressing the Button2, i can now set ListView.model to this new List Model i was created -
hi,
I've edited my reply accordingly.
thanks,
Max -
Thanks for your help.
At last i created that object)And i hope the last question is how to manipulate that object?
Take parent and compare all it's children to find the object i created, or there is some other way to handle it?