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. Settings: how to save the status of multiple switch in a page reused many time
Qt 6.11 is out! See what's new in the release blog

Settings: how to save the status of multiple switch in a page reused many time

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
24 Posts 4 Posters 4.3k Views 2 Watching
  • 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.
  • gfxxG gfxx

    @LeLev Yes not exist ... but because not exist parent attribute of Setting or is possible to make parent attribute of Settings?

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by JonB
    #13

    @gfxx
    swSE is your Settings, and esw0 is an attribute of that. I don't understand why you are trying to use parent? Now that I understand what you're trying to do, don't you simply intend: swSE["esw"+index]? (Whether that works or not is another matter.)

    gfxxG 1 Reply Last reply
    2
    • ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by ODБOï
      #14

      you can do like this

      Component.onCompleted: console.log( swSE.values[0]  )
          Settings {
              id: swSE
              property variant values : [false,false,true]
          ...
      

      but cant do this swSE["esw0"]

      1 Reply Last reply
      1
      • Shrinidhi UpadhyayaS Offline
        Shrinidhi UpadhyayaS Offline
        Shrinidhi Upadhyaya
        wrote on last edited by
        #15

        Hi @gfxx , you can do like this

        Here is a sample code:-

        Settings.qml

        Rectangle {
               id: root
        
               anchors.fill: parent
               color: "grey"
        
               property bool a0: false
               property bool a1: false
               property bool a2: false
               property bool a3: false
               property bool a4: false
               property bool a5: true
               property bool a6: true
               property bool a7: true
               property bool a8: true
               property bool a9: true
        }
        

        main.qml

         Settings {
                id: dummySettings
            }
        
        Component.onCompleted: {
                for(var i=0;i < 10;i++) {
                    console.log(dummySettings["a" + i])
                }
            }
        

        Shrinidhi Upadhyaya.
        Upvote the answer(s) that helped you to solve the issue.

        ODБOïO gfxxG 2 Replies Last reply
        1
        • Shrinidhi UpadhyayaS Shrinidhi Upadhyaya

          Hi @gfxx , you can do like this

          Here is a sample code:-

          Settings.qml

          Rectangle {
                 id: root
          
                 anchors.fill: parent
                 color: "grey"
          
                 property bool a0: false
                 property bool a1: false
                 property bool a2: false
                 property bool a3: false
                 property bool a4: false
                 property bool a5: true
                 property bool a6: true
                 property bool a7: true
                 property bool a8: true
                 property bool a9: true
          }
          

          main.qml

           Settings {
                  id: dummySettings
              }
          
          Component.onCompleted: {
                  for(var i=0;i < 10;i++) {
                      console.log(dummySettings["a" + i])
                  }
              }
          
          ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by ODБOï
          #16

          @Shrinidhi-Upadhyaya said in Settings: how to save the status of multiple switch in a page reused many time:

          Rectangle

          we are talking about Settings QML Type
          +sorry but your code does not make sense i belive.. , you can not iterate like that. What you can do in your example is :

          for (var i in dummySettings){
           console.log(i)
          }
          

          ...

          1 Reply Last reply
          0
          • Shrinidhi UpadhyayaS Offline
            Shrinidhi UpadhyayaS Offline
            Shrinidhi Upadhyaya
            wrote on last edited by Shrinidhi Upadhyaya
            #17

            Hi @LeLev , actually you guys were discussing about how you can access a variable for example like: esw0,esw1 etc and you have replied that you cant do this swSE["esw0"], but actually you can do it right, the code which i have written is just a sample code, you can replace the rectangle with Settings and inside that create 10variables like esw0,esw1 etc after you can access that in main.qml like the way i have done.

            According to you, we can access variable only by this way

            dummySettings.a0,dummySettings.a1
            

            But we can access the variable by the way i have done.

            If you copy paste my code, you will be able to see that,you will get the values printed in the console that means you are able to access the variable.

            Shrinidhi Upadhyaya.
            Upvote the answer(s) that helped you to solve the issue.

            ODБOïO gfxxG 3 Replies Last reply
            3
            • Shrinidhi UpadhyayaS Shrinidhi Upadhyaya

              Hi @LeLev , actually you guys were discussing about how you can access a variable for example like: esw0,esw1 etc and you have replied that you cant do this swSE["esw0"], but actually you can do it right, the code which i have written is just a sample code, you can replace the rectangle with Settings and inside that create 10variables like esw0,esw1 etc after you can access that in main.qml like the way i have done.

              According to you, we can access variable only by this way

              dummySettings.a0,dummySettings.a1
              

              But we can access the variable by the way i have done.

              If you copy paste my code, you will be able to see that,you will get the values printed in the console that means you are able to access the variable.

              ODБOïO Offline
              ODБOïO Offline
              ODБOï
              wrote on last edited by ODБOï
              #18

              @Shrinidhi-Upadhyaya said in Settings: how to save the status of multiple switch in a page reused many time:

              actually you can do it right

              yes, in fact we can, i didn't knew that

              @Shrinidhi-Upadhyaya said in Settings: how to save the status of multiple switch in a page reused many time:

              actually you guys were discussing about how you can access a variable for example like: esw0,esw1

              the original topic is "how to save Ui state"

              1 Reply Last reply
              0
              • Shrinidhi UpadhyayaS Shrinidhi Upadhyaya

                Hi @LeLev , actually you guys were discussing about how you can access a variable for example like: esw0,esw1 etc and you have replied that you cant do this swSE["esw0"], but actually you can do it right, the code which i have written is just a sample code, you can replace the rectangle with Settings and inside that create 10variables like esw0,esw1 etc after you can access that in main.qml like the way i have done.

                According to you, we can access variable only by this way

                dummySettings.a0,dummySettings.a1
                

                But we can access the variable by the way i have done.

                If you copy paste my code, you will be able to see that,you will get the values printed in the console that means you are able to access the variable.

                gfxxG Offline
                gfxxG Offline
                gfxx
                wrote on last edited by
                #19

                @all

                as I can understand ... is not possible "reuse" Settings because is only a table on Sqlite db. But these notice is only my suspicious, not other.
                If is right, every time the system make a query on that table (only one) these is not so flexible .... I think is better to use a db instead Settings. In these way I can insert my query create(if not exist) - insert - select - update on myPageComponent and with the use of property string myNewTable I can set outside from myPageComponent, for example in my mainPage or in my nestedMainPage, a new name of data table, so if i create for example 1000 new nested page, I have only the problem of set new table name, and I can make these with a for cicle for example .... better than 1000 of other things.

                Any how if someone have notice that these is possible using Settings .... please I need to know these.

                regards.

                bkt

                1 Reply Last reply
                0
                • JonBJ JonB

                  @gfxx
                  swSE is your Settings, and esw0 is an attribute of that. I don't understand why you are trying to use parent? Now that I understand what you're trying to do, don't you simply intend: swSE["esw"+index]? (Whether that works or not is another matter.)

                  gfxxG Offline
                  gfxxG Offline
                  gfxx
                  wrote on last edited by
                  #20

                  @JonB yes these work ... these is a news for my .... sorry. I'm a little bit confusing about QSettings work.

                  Any how in witch way these can be reused? Only make a new

                  Setting { id: newSetting1; }
                  

                  I think ..... and outside of NestedPage .... so I think I have to run iterate outside of nestedPage and the use per connect property has checked the setting .... a long story how can I see .. .. but it could be that I didn't understand all these things.

                  bkt

                  1 Reply Last reply
                  0
                  • Shrinidhi UpadhyayaS Shrinidhi Upadhyaya

                    Hi @LeLev , actually you guys were discussing about how you can access a variable for example like: esw0,esw1 etc and you have replied that you cant do this swSE["esw0"], but actually you can do it right, the code which i have written is just a sample code, you can replace the rectangle with Settings and inside that create 10variables like esw0,esw1 etc after you can access that in main.qml like the way i have done.

                    According to you, we can access variable only by this way

                    dummySettings.a0,dummySettings.a1
                    

                    But we can access the variable by the way i have done.

                    If you copy paste my code, you will be able to see that,you will get the values printed in the console that means you are able to access the variable.

                    gfxxG Offline
                    gfxxG Offline
                    gfxx
                    wrote on last edited by
                    #21

                    @Shrinidhi-Upadhyaya We actually discuss settings iterated and reuse the page with the settings inside it ... If I understand correctly, this is not possible.

                    regards

                    bkt

                    1 Reply Last reply
                    0
                    • Shrinidhi UpadhyayaS Shrinidhi Upadhyaya

                      Hi @gfxx , you can do like this

                      Here is a sample code:-

                      Settings.qml

                      Rectangle {
                             id: root
                      
                             anchors.fill: parent
                             color: "grey"
                      
                             property bool a0: false
                             property bool a1: false
                             property bool a2: false
                             property bool a3: false
                             property bool a4: false
                             property bool a5: true
                             property bool a6: true
                             property bool a7: true
                             property bool a8: true
                             property bool a9: true
                      }
                      

                      main.qml

                       Settings {
                              id: dummySettings
                          }
                      
                      Component.onCompleted: {
                              for(var i=0;i < 10;i++) {
                                  console.log(dummySettings["a" + i])
                              }
                          }
                      
                      gfxxG Offline
                      gfxxG Offline
                      gfxx
                      wrote on last edited by gfxx
                      #22

                      @Shrinidhi-Upadhyaya yes your code sample work in my app too .... but for use it I must:

                      *declare 100 property (if I have only 100 of these)
                      *on top of nested page iterate trought Setting file .... than connect the result on bottom nested page

                      I'm really new in qml. But as I understand I have to declare property bool axx for every single variable and the reuse of the page becomes boring to do :(

                      I'm in wrong?

                      if they are true ... it is better to use the old queries and a specific sqlite database for custom setting operations.

                      I appreciate any reply about.

                      regards

                      bkt

                      1 Reply Last reply
                      0
                      • Shrinidhi UpadhyayaS Offline
                        Shrinidhi UpadhyayaS Offline
                        Shrinidhi Upadhyaya
                        wrote on last edited by
                        #23

                        Hi @gfxx , iam sorry for understanding your question in a wrong way, i had thought that Settings is a different page.Okay but still if you want to use properties inside Settings type, you can do it in the way i have told.

                        I did not get your point "Settings Iterated", can you explain me a bit, so that i can help your or at least it can be helpful to me also.
                        And what do you mean by "100+ 100 declaration of property" ? did not get it actually!

                        Shrinidhi Upadhyaya.
                        Upvote the answer(s) that helped you to solve the issue.

                        gfxxG 1 Reply Last reply
                        0
                        • Shrinidhi UpadhyayaS Shrinidhi Upadhyaya

                          Hi @gfxx , iam sorry for understanding your question in a wrong way, i had thought that Settings is a different page.Okay but still if you want to use properties inside Settings type, you can do it in the way i have told.

                          I did not get your point "Settings Iterated", can you explain me a bit, so that i can help your or at least it can be helpful to me also.
                          And what do you mean by "100+ 100 declaration of property" ? did not get it actually!

                          gfxxG Offline
                          gfxxG Offline
                          gfxx
                          wrote on last edited by gfxx
                          #24

                          @Shrinidhi-Upadhyaya said in Settings: how to save the status of multiple switch in a page reused many time:

                          i had thought that Settings is a different page

                          I have main + some top nested page + some bottom nested page inside some one of the top nested. The most part is a reused page. So I need to save state of all switch control .... Is really a good ideas to use setting ? As I understand is not good. But I repeat I'm really new in qml.

                          100 + 100 is my error . ++sorry. I correct the post.

                          bkt

                          1 Reply Last reply
                          0

                          • Login

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