Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]Read multiple files using QSettings?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Read multiple files using QSettings?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 3.8k Views 1 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.
  • ealioneE Offline
    ealioneE Offline
    ealione
    wrote on last edited by
    #1

    How can I use QSettings to read multiple ini files within a for loop?

    So basically I read one file, store its contents somewhere and move on to another file until the loop ends, so ill have to use the same QSettings object until the end.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      You can't do that, you will only damage your data this way. Construct a new QSettings object (put it on a stack within the loop) for every file.
      @
      for (some; conditions; blah) {
      QSettings settings(path);
      // ...
      }
      @

      (Z(:^

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        Why?

        We use a multiple-configuration store solution, but it doesn't work using QSettings to read multiple files using a loop...

        Instead, we basically have a class that is our central settings interface in the application. That class decides per setting which of the underlying settings files (or registry) it will use for what setting, and who overrules who.

        1 Reply Last reply
        0
        • ealioneE Offline
          ealioneE Offline
          ealione
          wrote on last edited by
          #4

          I had an unknown number of files that I needed to read and parse. In any case I had to do something like

          for (some; conditions; blah) {
          QSettings* settings = new QSettings(path);
          // ...
          }

          in order to pass the settings object to the function responsible for saving stuff, I hope it is not a stupid move :)

          Thanks.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            As long as it is clear who will get rid of the QSettings instance once you have passed it to that function...

            1 Reply Last reply
            0
            • ealioneE Offline
              ealioneE Offline
              ealione
              wrote on last edited by
              #6

              Hey Andre,

              the thing with me though is that I have many files, each one with its' respective settings file, so I decided to read all those files and save them in a list structure. Not sure if its the smartest thing to do :P

              EDIT:
              Yes I do call settings.clear(); on every loop

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                In that case, why not create the instance on the stack in the first place?

                @
                for (some; conditions; blah) {
                QSetting settings(path);
                theProcessingFunction(&setting); // if you must use a pointer, a (const) reference would probably be better
                }
                @

                That's more efficient and less error phrone.

                1 Reply Last reply
                0
                • ealioneE Offline
                  ealioneE Offline
                  ealione
                  wrote on last edited by
                  #8

                  True, I don't intend to alter anything on "theProcessingFunction".

                  I will do that, thanks :)

                  I am though somewhat intrigued by your initial suggestion, if you ever write an article or a tutorial i'd be interested to follow.

                  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