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 Updated to NodeBB v4.3 + New Features

QSettings not returning keys of the predefined .ini file

Scheduled Pinned Locked Moved Solved General and Desktop
20 Posts 4 Posters 2.4k 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.
  • A Offline
    A Offline
    aha_1980
    Lifetime Qt Champion
    wrote on 1 Oct 2018, 07:40 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
    • R raven-worx
      1 Oct 2018, 07:37

      @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 1 Oct 2018, 07:41 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
        1 Oct 2018, 07:35

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

        R Offline
        R Offline
        raven-worx
        Moderators
        wrote on 1 Oct 2018, 07:42 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 Oct 2018, 07:50
        1
        • R raven-worx
          1 Oct 2018, 07:42

          @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 1 Oct 2018, 07:50 last edited by
          #13

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

          R 1 Reply Last reply 1 Oct 2018, 08:01
          0
          • T thippu
            1 Oct 2018, 07:50

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

            R Offline
            R Offline
            raven-worx
            Moderators
            wrote on 1 Oct 2018, 08:01 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 Oct 2018, 08:06
            1
            • R raven-worx
              1 Oct 2018, 08:01

              @thippu
              and? it's working now?

              T Offline
              T Offline
              thippu
              wrote on 1 Oct 2018, 08:06 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.

              R 1 Reply Last reply 1 Oct 2018, 08:20
              0
              • R raven-worx
                1 Oct 2018, 08:01

                @thippu
                and? it's working now?

                T Offline
                T Offline
                thippu
                wrote on 1 Oct 2018, 08:18 last edited by thippu 10 Jan 2018, 08:22
                #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
                  1 Oct 2018, 08:06

                  @raven-worx bro, in .ini

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

                  R Offline
                  R Offline
                  raven-worx
                  Moderators
                  wrote on 1 Oct 2018, 08:20 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 T 2 Replies Last reply 1 Oct 2018, 08:23
                  4
                  • R raven-worx
                    1 Oct 2018, 08:20

                    @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 Offline
                    J Offline
                    J.Hilk
                    Moderators
                    wrote on 1 Oct 2018, 08:23 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.

                    R 1 Reply Last reply 1 Oct 2018, 09:36
                    1
                    • R raven-worx
                      1 Oct 2018, 08:20

                      @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 1 Oct 2018, 08:25 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 J.Hilk
                        1 Oct 2018, 08:23

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

                        R Offline
                        R Offline
                        raven-worx
                        Moderators
                        wrote on 1 Oct 2018, 09:36 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

                        19/20

                        1 Oct 2018, 08:25

                        • Login

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