[Qt-qml] Global variables in QML
Jesper K. Pedersen
jesper.pedersen at kdab.com
Mon Jan 3 10:40:00 CET 2011
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: global.tgz
Type: application/x-compressed-tar
Size: 735 bytes
Desc: not available
Url : http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20110103/6c28620c/attachment.bin
More information about the Qt-qml
mailing list