Hi, I have a .js file which build several qml objects and store them in a global array.
This array is pretty important because all dynamically build objects are accessible with this array.
Now I'm working in a second .js file and I has to know which objects are existing.
I would refer the array from the first .js file but I don't get this to work.
I'm no JS guru or something like that.
As far as i know the only thing i had to do in HTML is to include both files in a page and thats it.
But what can I do in the qml environment to access an global array from file 1 in the context of file 2 ?
Thanks for help
I think you just need to add .pragma library reference in your js file and then the vars from it become available for all others.
Also some usefull info here re .pragma:
Ok this works pretty well so far.
Now I have access but other problems occur.
about the qml object itself.
Ok no problem so far, this could be handled by forwarding the objects as parameters.
But how to forward imports like enumerations etc. ?
I used some enums like EventDefinition.Hide from the qml object context.
Ok this wasn't so hard ; )
I just added the imported enum to the parameter list of the functions.
But I still have a problem with the array of qml objects.
The first step in the UI build process is to call various functions which build the qml objects and store them to the corresponding global arrays.
Thats not the problem but I have to be able to access the global arrays with all objects. But in the context of the Qml objects these global arrays are empty.
I'm a bit confused right now.
Has this something to do with the QDeclarativeContext in which the objects were created ?
I tried to verify this as far as i could.
In fact there is some kind of scope problem.
In my main Qml object lets call it "FirstLayer" I'm call on the Component.onCompleted signal
a javscript function which builds me different Qml objects using the Qt.createComponent() and component.createObject() functions.
After this is finisched the "FirstLayer" object has two "Screen" objects and each "Screen" has at least four "Button" objects.
But although I declare the .js file which contains the array as .pragma library I didn't access the same arrays within the context of the "Screen" or "Button" objects. In their context these arrays are still empty.
So it looks like they are initializing there own instances of these arrays.
And I have no idea how to solve this.
So if anybody has an idea how I can fix that.
Please let me know.
Thanks for any help guys.