Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML how to save variable value while changing to anothe qml.
Forum Update on Monday, May 27th 2025

QML how to save variable value while changing to anothe qml.

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 289 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gunkut
    wrote on 3 May 2021, 05:28 last edited by
    #1

    I want to save the value of a variable when I change the QML and then come back to the same qml again. How can I do that? The valuıe gets zeroed after when I open the corresponding QML.
    I open new qml from my main.qml by using loader.

    RightButtons
    {
         MultiPointTouchArea
    {
         onPressed:
    {
         pageLoader.source="CTISpage.qml"
    }
    }
    }
    

    And here is my loader

    Loader
    {
         id:pageLoader
         Connections
    {
         target:pageLoader.item
         onBackButtonPressed:
    {
         pageLoader.source=""
    }
    }
    }
    

    So when I press the button I set the loader new source and open the page, and from the new page when I press the back button, I set source of loader to an empty string and make it return to my main.qml.

    Here is the problem: In the new qml I use a boolean variable and I want to save it's value between going back to main.qml and returning to this qml. But it gets zeroed all the time in this process. Here is what my new qml looks like:

    Item
    {
         id: CTISPage.qml
         .
         .
         .
    signal backButtonPressed()
    property var isABSOffRoad:false:false
    
    .
    .
    .
    
    LeftButtons
    {
       MultiPointTouchArea
    {
       onPressed:
    {
        isABSOffRoad=!isABSOffRoad
    if(ABSOffRoad)
    {
    //Do sth if it is true
    }
    }
    }
    }
    }
    

    When I press the button and set the boolean isABSOffRoad variable to true, it gets false when I go back to main and come back to this qml again. I also tried to declared the boolean variable in main and then reach that variable from this qml. However, the result is same. I also tried to open a new variables.qml file and declared all that variables in that qml and reach them from there. But that did not work either. How can I find a way around for this?

    1 Reply Last reply
    1

    1/1

    3 May 2021, 05:28

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved