[Qt-qml] Global variables in QML

Jesper K. Pedersen jesper.pedersen at kdab.com
Mon Jan 3 12:05:01 CET 2011


Thanks for your answer, this was exactly what I was looking for.

Cheers
Jesper.

On Monday 03 January 2011 11:20:17 aaron.kennedy at nokia.com wrote:
> Hi,
> 
> Add ".pragma library" to the top of the js file.
> 
> Cheers,
> 
> Aaron
> ________________________________________
> From: qt-qml-bounces+aaron.kennedy=nokia.com at qt.nokia.com
> [qt-qml-bounces+aaron.kennedy=nokia.com at qt.nokia.com] on behalf of ext
> Jesper K. Pedersen [jesper.pedersen at kdab.com] Sent: Monday, January 03,
> 2011 7:40 PM
> To: qt-qml at qt.nokia.com
> Subject: [Qt-qml] Global variables in QML
> 
> 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

-- 
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


More information about the Qt-qml mailing list