Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Defining global variable in QML

From 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 19:33.
171 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×