Namespaces
Variants
Actions
Revision as of 04:20, 11 October 2012 by hamishwillee (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Defining global variable in QML

Jump to: navigation, search
Article Metadata

Tested with
Devices(s): Nokia E7, Nokia N8, Nokia N900

Compatibility
Platform(s): Symbian
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.

359 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved