Defining global variable in QML
Article Metadata
Tested with
Devices(s): Nokia E7, Nokia N8, Nokia N900
Compatibility
Platform(s): Symbian
Maemo
Maemo
Article
Keywords: JavaScript
Created: tepaa
(14 Jan 2011)
Last edited: hamishwillee
(11 Oct 2012)
Contents |
Overview
This snippet shows how to define global variable in QML using JavaScript. User cannot define global variables in QML code.
This snippet was used in the Nokia Developer example QuickHit
Preconditions
None.
JavaScript -file
For example Game.js file contains levelPlugin global JavaScript variant variable.
// Global variable in JavaScript file
var levelPlugin = null
Using global variable in QML
Example of QML file. Global variable can be used after importing JavaScript.
// Import JavaScript Game.js file as GameScript alias
import "Game.js" as GameScript
// Using global variable in QML function
if (GameScript.levelPlugin) {
console.log("levelPlugin exists")
} else {
console.log("levelPlugin is NULL")
}
Postconditions
Global variable can be used in QML.


(no comments yet)