Can we declare global variable in QML file?

psp1 picture psp1 · Sep 22, 2011 · Viewed 22.6k times · Source

I want to do something similer to following code:

//test.qml
import QtQuick 1.0
Item 
{
    var globalforJs =10;

    function increment() // JavaScript function
    {
        globalforJs++;
    }
    ....
QML Code

Can we have global variable in QML file and access it from the JavaScript function?

Answer

coyotte508 picture coyotte508 · Sep 22, 2011

Try property int globalForJs: 10;

If you want a variable that can take any type:

property var globalForJs: 10

Prior to QML 2, use the variant keyword instead of var.