×
Namespaces

Variants
Actions

Defining global variable in QML

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Nokia E7, Nokia N8, Nokia N900
Compatibility
Platform(s): Symbian
Maemo
Symbian
Article
Keywords: JavaScript
Created: tepaa (14 Jan 2011)
Last edited: kiran10182 (31 Oct 2013)


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.

This page was last modified on 31 October 2013, at 22:33.
159 page views in the last 30 days.
×