OK, so, it seems I’m having one issue after another, and here is my latest. I have a dynamically created ListModel created in Javascript with Qt.createQmlObject(), then I have a dynamically created GridView also created in Javascript with Qt.createQmlObject(), which needs to set it’s model to the dynamically created model. Now I can not figure out how to do this for the life of me, because dynamically created objects have no QML id. The model is added to my root element, I’ve tried ‘model: root.myModelID’ just to see if it would work, and of course it didn’t.
Now from what I understand a dynamically created object can only be accessed from the object returned by Qt.createQmlObject(), so I even tried making making a globalvars.js file, declaring ‘var model;’ in the file, including it in my QML file, then returning my dynamically created model as such:
globalvars.js:
var myModel;
QML file:
import "globalvars.js" as Vars
// Then later I have this
Component.onCompleted: {
Vars.myModel = createMyModel(); /* The ListModel created by Qt.createQmlObject() is returned */
createMyGridView(); /* This is where I use Qt.createQmlObject() to create a GridView, which is then trying to use Vars.myModel as the model */
}
Now when I try that, it throws the error: ‘ReferenceError: Vars is not defined’
This is getting very frustrating, I need to figure out a way to set the model, I tried to search to see if GridView has a method to set the model, because that would solve my problem as I wouldn’t have to have it set the model in the dynamic creation (in Qt.createQmlObject()), I could just pass myModel to createMyGridView(), then call the Javascript method of myGridView, but GridView has no method to set the model.
I hope my question makes sense, if it doesn’t please let me know and I’ll try to clarify further. Any help is greatly apprecieated.
↧