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. 'general' settings section works incorrectly
Qt 6.11 is out! See what's new in the release blog

'general' settings section works incorrectly

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 4.2k 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.
  • D Offline
    D Offline
    Dmitriano
    wrote on last edited by Dmitriano
    #1

    If I set general/serviceMode key to 'true' using QSettings in this way:

    static const char * serviceModeKey = "general/serviceMode";
    
    QSettings qSettings(settingsFileName(), QSettings::IniFormat);
    
    bool val =  qSettings.value(serviceModeKey, false).value<bool>();
    
    bool other_val = true;
    
    qSettings.setValue(serviceModeKey, other_val);
    
    

    'general' section is duplicated, so settings file looks like this:

    [%General]
    serviceMode=true

    ...

    [%General]
    serviceMode=true

    ...

    and the value is false when the app starts next time.

    if I rename the key with 'app/serviceMode', for example, it seems to work fine.

    I use QT 5.9.1, Ubuntu Linux

    JonBJ 1 Reply Last reply
    0
    • D Dmitriano

      If I set general/serviceMode key to 'true' using QSettings in this way:

      static const char * serviceModeKey = "general/serviceMode";
      
      QSettings qSettings(settingsFileName(), QSettings::IniFormat);
      
      bool val =  qSettings.value(serviceModeKey, false).value<bool>();
      
      bool other_val = true;
      
      qSettings.setValue(serviceModeKey, other_val);
      
      

      'general' section is duplicated, so settings file looks like this:

      [%General]
      serviceMode=true

      ...

      [%General]
      serviceMode=true

      ...

      and the value is false when the app starts next time.

      if I rename the key with 'app/serviceMode', for example, it seems to work fine.

      I use QT 5.9.1, Ubuntu Linux

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

      @Dmitriano
      I know nothing, but is there an issue with your key being "general... and your file containing [%General...?

      D 1 Reply Last reply
      1
      • JonBJ JonB

        @Dmitriano
        I know nothing, but is there an issue with your key being "general... and your file containing [%General...?

        D Offline
        D Offline
        Dmitriano
        wrote on last edited by Dmitriano
        #3

        @JNBarchan Yes, it not clear enough what is the issue, but at least looks like something is wrong with QSettings.

        JonBJ 1 Reply Last reply
        0
        • D Dmitriano

          @JNBarchan Yes, it not clear enough what is the issue, but at least looks like something is wrong with QSettings.

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

          @Dmitriano
          I use QSettings under Linux but there is no % in the .ini file (all my sections/items start with uppercase though)....

          D 1 Reply Last reply
          0
          • JonBJ JonB

            @Dmitriano
            I use QSettings under Linux but there is no % in the .ini file (all my sections/items start with uppercase though)....

            D Offline
            D Offline
            Dmitriano
            wrote on last edited by
            #5

            @JNBarchan did you try 'general' section? Probably it is a special case.

            JonBJ 1 Reply Last reply
            0
            • D Dmitriano

              @JNBarchan did you try 'general' section? Probably it is a special case.

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

              @Dmitriano
              Yep, I see. Please try naming your key "General/... instead of "general/... ? You also need to look at:

              The INI file format has severe restrictions on the syntax of a key. Qt works around this by using % as an escape character in keys. In addition, if you save a top-level setting (a key with no slashes in it, e.g., "someKey"), it will appear in the INI file's "General" section. To avoid overwriting other keys, if you save something using a key such as "General/someKey", the key will be located in the "%General" section, not in the "General" section.

              If you still have trouble, suggest removing the leading "general" from your key entirely and change .ini entry to [General] and and see if that resolves better.

              D 1 Reply Last reply
              1
              • JonBJ JonB

                @Dmitriano
                Yep, I see. Please try naming your key "General/... instead of "general/... ? You also need to look at:

                The INI file format has severe restrictions on the syntax of a key. Qt works around this by using % as an escape character in keys. In addition, if you save a top-level setting (a key with no slashes in it, e.g., "someKey"), it will appear in the INI file's "General" section. To avoid overwriting other keys, if you save something using a key such as "General/someKey", the key will be located in the "%General" section, not in the "General" section.

                If you still have trouble, suggest removing the leading "general" from your key entirely and change .ini entry to [General] and and see if that resolves better.

                D Offline
                D Offline
                Dmitriano
                wrote on last edited by
                #7

                @JNBarchan at least I did not name my section '%General'. Where to report 'General' section duplication as a bug?

                jsulmJ 1 Reply Last reply
                0
                • D Dmitriano

                  @JNBarchan at least I did not name my section '%General'. Where to report 'General' section duplication as a bug?

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Dmitriano https://bugreports.qt.io/secure/Dashboard.jspa

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  D 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @Dmitriano https://bugreports.qt.io/secure/Dashboard.jspa

                    D Offline
                    D Offline
                    Dmitriano
                    wrote on last edited by
                    #9

                    @jsulm reported this as a bug here https://bugreports.qt.io/browse/QTBUG-63694

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Hi,

                      From a quicklook, general is a keyword used in the Qt sources in qsettings.cpp.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      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