ubuntu-phone team mailing list archive
-
ubuntu-phone team
-
Mailing list archive
-
Message #02006
Re: Global variables in QML
W dniu 22.05.2013 19:49, Aleksandar Jovanov pisze:
> I am not much of a writer so I will just write about my experiences on
> this topic which can get very annoying if not understood well.
--8<--
> My second attempt :
>
> Defining all my globals in the root qml object. This made a lot of sense
> and worked fine for some time, before it broke today.
> I am not sure why that happened :)
>
> MainView {
> property int globalNumber : 12; // no, doesn't work too,
> undefined reference to globalNumber errors
> }
If you've given an id (say, main) to the MainView, you should be able to
access it via main.globalNumber just fine. Not that that is a good thing
to do...
> My third (and hopefully final attempt) :
>
> I created a dictionary in Qt that stays persistent accross the
> application lifecycle. I've also added a bit of sugar over it.
> Here is the code for that :
Feels overkill...
Stateless libraries [1] should be what you need. And [2] supports that.
[1]
http://qt-project.org/doc/qt-5.0/qtqml/qtqml-javascript-resources.html#shared-javascript-resources-libraries
[2] http://pastebin.ubuntu.com/5691465/
--
Michał Sawicz <michal.sawicz@xxxxxxxxxxxxx>
Canonical Services Ltd.
Attachment:
signature.asc
Description: OpenPGP digital signature
References