[Qt-qml] Global variables in QML
Girish Ramakrishnan
girish at forwardbias.in
Mon Jan 3 11:09:57 CET 2011
You should add the line ".pragma library" at the beginning of your js.
For more information, see
http://doc.qt.nokia.com/latest/qdeclarativejavascript.html#stateless-javascript-libraries.
Girish
On Mon, Jan 3, 2011 at 3:10 PM, Jesper K. Pedersen
<jesper.pedersen at kdab.com> wrote:
> Please have a look at the attached small QML application.
>
> I have two QML files, which uses a shared JavaScript file. The JavaScript file
> declares a global variable - well that is what I believed it was, but in
> reality, it is global to the QML file it is used from.
>
> Try running it, and you will see that global.qml and Block.qml each seems to
> have their own local instance of the global variable.
>
> Now the question is, is this a feature or a bug?
> And if it is a feature, how do I get a true global variable?
>
> Actually, I already have a few solutions:
> 1) Make the variable a property on a QML object. That will, however, not work
> for complex data types like a map
> 2) Make the data live in C++ - will not work if I want a QML only project.
>
> Cheers
> Jesper.
> --
> Jesper K. Pedersen | jesper.pedersen at kdab.com
> Senior Software Engineer and Global Training Manager
> Klarälvdalens Datakonsult AB, a KDAB Group company
> Tel. Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322)
> KDAB - Qt Experts - Platform-independent software solutions
>
> _______________________________________________
> Qt-qml mailing list
> Qt-qml at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-qml
>
>
More information about the Qt-qml
mailing list