The replacement of "window" object in Javascript
-
Whatever we declared a global variable in Javascript under browser, it will be added to the "window" object automatically. Then we could check did a global variable/object declared by looking at the window object.
However, it don't have "window" object in Qt Quick. Do it have any replacement? So that I can check did a global variable declared?
Thanks.
-
In Qt Quick, global stuff (for QML and JS) is added to the rootContext of the QML engine. You access it directly, without specifying any parent object.
As for pure JavaScript, AFAIK, all contexts are separate, so you can't specify anything truly global. But my knowledge of JS is too limited to say for sure.
-
Thanks for your reply. In fact, I would like to configure the variable of a Javascript instance and the method I chosen is context object. However, as the context object is passed by the C++ program, it will throw "Reference Error" under Qt Designer.
To avoid the error , I would like to check did the context object / global variable declared before access. But unfortunately it don't have the "window" object under Qt Quick.
-
@
if (someObject == undefined) {
// it is not defined
} else {
// we are good to go :)
}
@ -
That will throw :
@
ReferenceError: someObject is not defined
@
1/5