[Interest] QML global variables?
Jérôme Godbout
jerome at bodycad.com
Tue Jan 6 20:14:48 CET 2015
You can try to use a singleton, seem like what you need.
Inside qmldir:
*singleton Settings 1.0 Settings.qml*
At the beginning of Settings.qml
*pragma Singleton*
*// import goes here*
*QObject*
*{*
*property var appData*
*}*
Then you can use the *Settings.appData*
Or you can use the cascading into scope. Each your screen should be able to
reach the Windows id (make sure to never use it again)
*Main.qml*
*Window *
*{ *
* id: windowsUniqueId_*
* property var appData*
* Screen1 {}*
* Screen2 {}*
*}*
*Screen1,2,3.qml:*
*Rectangle*
*{*
* property var screenData: windowsUniqueId_.appData*
*}*
Note: If your data are js dictionary make sure to merge left or right the
data before assignation.
On Tue, Jan 6, 2015 at 2:02 PM, Jason H <jhihn at gmx.com> wrote:
> What is the proper way to declare a dynamic global?
>
> Currently my app is set up with
> main.qml:
> Window {
> property var AppData;
> Screen1 { onEnter: { screen1.screenData = appData.screen1 }, onExit: {
> appData.screen1 = screen1.screenData }}
> Screen2 { onEnter: { screen2.screenData = appData.screen2 }, onExit: {
> appData.screen2 = screen2.screenData }}
> Screen3 { onEnter: { screen3.screenData = appData.screen3 }, onExit: {
> appData.screen3 = screen3.screenData }}
> }
>
> Screen1,2,3.qml:
> Rectangle {
> property var screenData;
> }
>
> I'd like to just have the screens and Window reference the same variable
> so I don't have to keep moving the data around because now I have async
> things (data load) happening between screens.
>
>
> Thanks
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150106/f28a7290/attachment.html>
More information about the Interest
mailing list