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. QSettings not returning keys of the predefined .ini file
Forum Update on Monday, May 27th 2025

QSettings not returning keys of the predefined .ini file

Scheduled Pinned Locked Moved Solved General and Desktop
20 Posts 4 Posters 2.4k 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.
  • raven-worxR raven-worx

    @thippu said in QSettings not returning keys of the predefined .ini file:

    iniSettings->setPath(QSettings::IniFormat,QSettings::UserScope,filename);// filename is a global variable here
    //If I do the following codes
    qDebug()<<iniSettings->group();//returns " "
    qDebug()<<iniSettings->allKeys();//returns ()

    you need to call QSettings::beginGroup() before reading/writing
    also you can check if the return value of QFile::exists(filename) if the application really can find your ini-file.

    T Offline
    T Offline
    thippu
    wrote on last edited by
    #7

    @raven-worx Yes, I did qDebug()<<QFile(filename).exists(); it returned me true.

    1 Reply Last reply
    0
    • raven-worxR raven-worx

      @thippu said in QSettings not returning keys of the predefined .ini file:

      iniSettings->setPath(QSettings::IniFormat,QSettings::UserScope,filename);// filename is a global variable here
      //If I do the following codes
      qDebug()<<iniSettings->group();//returns " "
      qDebug()<<iniSettings->allKeys();//returns ()

      you need to call QSettings::beginGroup() before reading/writing
      also you can check if the return value of QFile::exists(filename) if the application really can find your ini-file.

      T Offline
      T Offline
      thippu
      wrote on last edited by
      #8

      @raven-worx for beginGroup() , iniSetting->beginGroup("[");// I doubt it will work as per .ini filestructure?

      raven-worxR 2 Replies Last reply
      0
      • T thippu

        @raven-worx for beginGroup() , iniSetting->beginGroup("[");// I doubt it will work as per .ini filestructure?

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by raven-worx
        #9

        @thippu
        with respect to your ini file from your first post you should call:

        iniSettings->beginGroup("Personal");
        iniSettings->value("Age");
        iniSettings->endGroup();
        

        or alternatively (if you don't have a group set!):

        iniSettings->value("Personal/Age");
        

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        T 1 Reply Last reply
        1
        • aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #10

          @thippu

          And in addition to what @raven-worx says, you need to use this constructor if you want to specify the filename.

          Otherwise QSettings calculates the filename itself.

          Qt has to stay free or it will die.

          1 Reply Last reply
          3
          • raven-worxR raven-worx

            @thippu
            with respect to your ini file from your first post you should call:

            iniSettings->beginGroup("Personal");
            iniSettings->value("Age");
            iniSettings->endGroup();
            

            or alternatively (if you don't have a group set!):

            iniSettings->value("Personal/Age");
            
            T Offline
            T Offline
            thippu
            wrote on last edited by
            #11

            @raven-worx Yes bro, in that .ini example, [groupname] // may grow and I want to scan them dynamically, how to do it?

            1 Reply Last reply
            0
            • T thippu

              @raven-worx for beginGroup() , iniSetting->beginGroup("[");// I doubt it will work as per .ini filestructure?

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #12

              @thippu
              yes i just wanted to add as @aha_1980 said.
              Use the mentioned constructor, since in your case it is not required to mess with the scopes.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              T 1 Reply Last reply
              1
              • raven-worxR raven-worx

                @thippu
                yes i just wanted to add as @aha_1980 said.
                Use the mentioned constructor, since in your case it is not required to mess with the scopes.

                T Offline
                T Offline
                thippu
                wrote on last edited by
                #13

                @raven-worx okay, I have included in the constructor itself.
                code: iniSettings=new QSettings(filename,QSettings::IniFormat,this);

                raven-worxR 1 Reply Last reply
                0
                • T thippu

                  @raven-worx okay, I have included in the constructor itself.
                  code: iniSettings=new QSettings(filename,QSettings::IniFormat,this);

                  raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by
                  #14

                  @thippu
                  and? it's working now?

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  T 2 Replies Last reply
                  1
                  • raven-worxR raven-worx

                    @thippu
                    and? it's working now?

                    T Offline
                    T Offline
                    thippu
                    wrote on last edited by
                    #15

                    @raven-worx bro, in .ini

                    ) can grow, I want to scan them dynamically, so what to include in
                    beginGroup() ?, please help me.

                    raven-worxR 1 Reply Last reply
                    0
                    • raven-worxR raven-worx

                      @thippu
                      and? it's working now?

                      T Offline
                      T Offline
                      thippu
                      wrote on last edited by thippu
                      #16

                      @raven-worx Yes, bro working. failure was the happing because of the constructor, after setting it properly it working now, I did
                      I can't thank enough to guys @raven-worx , @aha_1980

                      qDebug()<<iniSettings->childGroups();//returns all the heading names````
                      1 Reply Last reply
                      0
                      • T thippu

                        @raven-worx bro, in .ini

                        ) can grow, I want to scan them dynamically, so what to include in
                        beginGroup() ?, please help me.

                        raven-worxR Offline
                        raven-worxR Offline
                        raven-worx
                        Moderators
                        wrote on last edited by
                        #17

                        @thippu
                        with the usage of the right Constructor your ini-file should be read correctly now.
                        So now you can use QSettings::childGroups() to traverse all groups and read the values as i described above or with the use of QSettings::beginGroup() and QSettings::childKeys()

                        foreach( QString group, iniSettings->childGroups() )
                        {
                             // process group
                             iniSettings->beginGroup(group);
                                 foreach( QString key, iniSettings->childKeys() )
                                 {
                                        QVariant val = iniSettings->value(key);
                                        // process val
                                 }
                             iniSettings->endGroup();
                        }
                        

                        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                        If you have a question please use the forum so others can benefit from the solution in the future

                        J.HilkJ T 2 Replies Last reply
                        4
                        • raven-worxR raven-worx

                          @thippu
                          with the usage of the right Constructor your ini-file should be read correctly now.
                          So now you can use QSettings::childGroups() to traverse all groups and read the values as i described above or with the use of QSettings::beginGroup() and QSettings::childKeys()

                          foreach( QString group, iniSettings->childGroups() )
                          {
                               // process group
                               iniSettings->beginGroup(group);
                                   foreach( QString key, iniSettings->childKeys() )
                                   {
                                          QVariant val = iniSettings->value(key);
                                          // process val
                                   }
                               iniSettings->endGroup();
                          }
                          
                          J.HilkJ Offline
                          J.HilkJ Offline
                          J.Hilk
                          Moderators
                          wrote on last edited by
                          #18

                          @raven-worx
                          uh hu, using deprecated syntax/macros, shame on you ;-)


                          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                          Q: What's that?
                          A: It's blue light.
                          Q: What does it do?
                          A: It turns blue.

                          raven-worxR 1 Reply Last reply
                          1
                          • raven-worxR raven-worx

                            @thippu
                            with the usage of the right Constructor your ini-file should be read correctly now.
                            So now you can use QSettings::childGroups() to traverse all groups and read the values as i described above or with the use of QSettings::beginGroup() and QSettings::childKeys()

                            foreach( QString group, iniSettings->childGroups() )
                            {
                                 // process group
                                 iniSettings->beginGroup(group);
                                     foreach( QString key, iniSettings->childKeys() )
                                     {
                                            QVariant val = iniSettings->value(key);
                                            // process val
                                     }
                                 iniSettings->endGroup();
                            }
                            
                            T Offline
                            T Offline
                            thippu
                            wrote on last edited by
                            #19

                            @raven-worx Sure bro, I will use this code to create group and contents of the group.

                            1 Reply Last reply
                            0
                            • J.HilkJ J.Hilk

                              @raven-worx
                              uh hu, using deprecated syntax/macros, shame on you ;-)

                              raven-worxR Offline
                              raven-worxR Offline
                              raven-worx
                              Moderators
                              wrote on last edited by
                              #20

                              @J.Hilk said in QSettings not returning keys of the predefined .ini file:

                              uh hu, using deprecated syntax/macros, shame on you ;-)

                              yes, i am still too lazy for such a convenient function to deprecate it also in my head ;)

                              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                              If you have a question please use the forum so others can benefit from the solution in the future

                              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