Javascript in qml error.
-
So in your javascript try:
@
.pragma libraryfunction getTitle(model, index){
return model.get(index).title;
}
@And in your qml Chk.getTitle(model, index);
Note that I'm not sure you can directly use model in your JavaScript I remember reading some sync stuff but I don't remember exactly what it was (maybe to do with WorkerScript element).
-
Just for later, sync must be applied when changing models from WorkerScripts.
See:
"ListModel documentation":http://qt-project.org/doc/qt-4.8/qml-listmodel.html#using-threaded-list-models-with-workerscript -
Nope the above js does not work. TypeError: Result of expression 'model.get' [undefined] is not a function.
-
I tried this in the same .qml file and I got this error
@Component.onCompleted: {
console.log(model.get(1).title);
}@
TypeError: Result of expression 'model.get(1)' [undefined] is not an object.
Qml debugging is enabled. Only use this in a safe environment! -
Are you sure model has items when the function is called? (i.e: is the function called after setting model data?)
-
yes.. the above code is the one am currently using. If you have some time kindly check it and let me know. thanks in advance
-
width:400
height:width
property int index:0ListView {
width: 180; height: 300
model: model
delegate: Text { text:title+ ": " + pubDate+id
}
XmlListModel {
id: model
source: "example.xml"
query: "/rss/channel/item"XmlRole { name: "title"; query: "title/string()" } XmlRole { name: "pubDate"; query: "pubDate/string()" } XmlRole { name: "id"; query: "id/string()" }}
}
Component.onCompleted:console.log(model.get(0).title);
}@
-
I get_TypeError: Result of expression ‘model.get(1)’ [undefined] is not an object.
Qml debugging is enabled. Only use this in a safe environment! -
The javascrpit does not recognize the qml file. any idea on how to link js and qml
-
[Solved] I passed the model as a js function. if there is any other alternative kindly let me know.