Writing a value to a seperate QML page



  • Hi,
    I've got an app which currently has multiple pages all contained within 1 QML file (Main.qml). I've been messing about with splitting the various pages into several QML files - so Main.qml, Setting.qml, etc. So far, it's (mostly) all working as expected. One exception is 'theme' - the settings page contains a list view allowing the user to switch between 'themes' - select the appropriate option and the app theme changes immediately.
    Separating the two, however, the theme doesn't change immediately - only after restarting the app. The selected theme is read from a Text field (in Main.qml), which itself reads from a U1DB value. The U1DB value is written to from a ListView in Settings.qml.
    I can see, when changing the value in Settings.qml, that the value in U1DB changes immediately (I have another text field in Settings.qml reading the appropriate index). However, the field in Main.qml (which reads from the same index) stays the same until the app is restarted.
    Anyone have any idea how to make the Text field in Main.qml read the U1DB index 'live'? I've tried a timer to refresh the value, but it doesn't appear to make any difference.
    It's not super important - the user can always select the theme and restart the app to apply - more curiosity and a desire to retain previous functionality.
    Thanks
    Mick



  • @Mick21367
    Hi Mick,
    It will be easier with a link to your code (on gitlab for example), but I'll try to give you some hints.

    You're probably reading the U1DB value onCompleted so it is not refreshed on change.
    I guess the entry point for theme value is in Main.qml, so you should have a property there that needs updating (linked to your text field).
    If Settings.qml is called from Main.qml, you may be able to access Main.qml's properties.

    So where you're writing the U1DB value from Settings.qml, you can also update the property for Main.qml directly...



  • Hi AppLee,
    You're right - I should have linked to the source code 🙂 - it's at : - https://bazaar.launchpad.net/~aurora-l/iquit/main/files/head:/qml. The two files in question are Main.qml (this is where the U1DB fields are loaded, I believe) and Settings.qml (this is where the field is written to). It's a bit messy, I afraid.
    I think you are right with the onCompleted though I don't understand why it would change before (when it was all contained in one file). I think it may be a problem with referencing an 'external' qml page, rather than an 'internal' page? I've tried writing to the field in Main.qml but it usually comes back with a reference not found error.
    Anyway, thanks again for replying 🙂



  • @Mick21367
    You're welcome ; after-all that's what the forum is for 😉
    I had a quick look at your code, you can try onCurrentPageChanged for the PageStack and see if the property d9 is changed on this event.
    If not, you may want to force the property to be updated from the DB...

    I'm going out, so I'll have another look later. 🤞



  • Hi AppLee, Thanks for that - it's much appreciated :-). I fiddled about with onCurrentPageChanged a bit but couldn't find much documentation on it, so failed to make much progress. I did find some stuff on the pageStack, though - I've found a (probably terrible) workaround by adding the following line to the onDelegateClicked action of the ItemSelector os2 in Settings.qml (the theme selector) - pageStack.push(page0, {message: d9=appdata9.contents.theme});. It appears to work OK, though there is a console error (" Property 'push' of object AdaptivePageLayout_QMLTYPE_62(0x17de290) is not a function
    ") so I'm not sure if I'm breaking anything with this?



  • @Mick21367
    Have you tried with mainStack.push() instead...

    pageStack is an attribute from page0 but I don't find documentation about it...
    the object returned by page0.pageStack seems to be AdaptativePageLayout when you want to access the PageStack object called mainStack.

    But there is maybe something better.
    Since you have access to page0 and/or mainStack you can probably update d9 directly.
    d9 = appdata9.contents.theme in the onDelegateClicked



  • @AppLee
    Updating d9 directly, as you suggested, worked a treat 🙂 - I didn't realise it could be done so simply, but I'm happy that's the case :-).
    Thank you so much for all your help - it's been invaluable.



  • @Mick21367 You're welcome.
    I'm happy it worked as expected. 👍


Log in to reply