Variable declarations
-
How do I declare a global and non-global variable?
I tried "var Key = 1"
but I am having error when I try to debug. -
You can include a .js file and use "var key = 1" in this js file, your variable will be visible in the QML file.
I don't know if there is a way of declaring "global" variable for all QML files.
-
bq. I don’t know if there is a way of declaring “global” variable for all QML files.
yes, with
@.pragma library
vak key = 1;@on top of the .js code
Edit: if I remember well, in Creator when you create a new .js file, it asks about create a stateless library
Edit 2: "here":http://qt-project.org/doc/qt-4.8/qdeclarativejavascript.html#stateless-javascript-libraries a reference -
Thanks for the link.
I have looked a time ago and the documentation was not so good, so at that time i did not succeed, ( didn't use Qt.include("factorial.js") in another js! ) but it works!