Hi,

In my program i have to access and change the value of a variable from different QML-files and from Javascript-files.
I'm using a JavaScript file to store the value:
Qt Code:
  1. //GlobalData.js
  2.  
  3. .pragma library
  4. var myValue = 42;
To copy to clipboard, switch view to plain text mode 

In my QML-files i use the variable like this:
Qt Code:
  1. //example.qml
  2.  
  3. import "GlobalData.js" as GData
  4.  
  5. ...
To copy to clipboard, switch view to plain text mode 

Everything works fine. There is only one instance of the GlobalData.js file and every QML-document can read and write myValue.

But now, i included GlobalData.js into a JavaScript like this:
Qt Code:
  1. //myJavaScript.js
  2.  
  3. Qt.include("GlobalData.js");
  4. console.log(myValue);
To copy to clipboard, switch view to plain text mode 

The problem is, that myJavaScript.js seems to create its own instance of GlobalData.js, so that if I modify myValue in a QML-Document, it's not changing in myJavaScript.js.


Is there any possibility to let myJavaScript access the same instance of GlobalData.js as the QML-Documents do, instead of creating its own one?


Thank You for your help