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 writes duplicate sections with strange names in ini-file
QtWS25 Last Chance

QSettings writes duplicate sections with strange names in ini-file

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 3.1k 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.
  • B Offline
    B Offline
    bear_dk
    wrote on last edited by
    #1

    Hi

    I'm using Qt 5.2 and get a strange looking ini-file when saving changes. Some sections appear twice with duplicate names:

    @[%General]
    ptt-key=-1, 111
    push-to-talk=true
    voice-activated=false

    [display]
    desktop-splitter=@ByteArray(\0\0\0\xff\0\0\0\0\0\0\0\x2\xff\xff\xff\xff\xff\xff\xff\xff\x1\0\0\0\x5\x1\0\0\0\x2)
    filesheader="@ByteArray(\0\0\0\xff\0\0\0\0\0\0\0\x1\0\0\0\x1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x1,\0\0\0\x3\x1\0\0\x1\0\0\0\0\0\0\0\0\0\0\0\0\x64\xff\xff\xff\xff\0\0\0\x81\0\0\0\0\0\0\0\x3\0\0\0\x64\0\0\0\x1\0\0\0\0\0\0\0\x64\0\0\0\x1\0\0\0\0\0\0\0\x64\0\0\0\x1\0\0\0\0)"
    splitter=@ByteArray(\0\0\0\xff\0\0\0\0\0\0\0\x2\0\0\x1\0\0\0\x1\f\x1\0\0\0\a\x1\0\0\0\x1)
    windowposition=291, 138, 637, 545

    [%General]
    push-to-talk=true
    voice-activated=false

    [soundsystem]
    mastervolume=255
    microphonegain=1000
    voice-activation-level=0@

    Why has "general" section been renamed to "%General" and why does the same keys appear twice?

    I instantiate my QSettings like this:

    @ttSettings = new QSettings(QSettings::IniFormat,
    QSettings::UserScope,
    QApplication::organizationName(),
    QApplication::applicationName(), this);
    @

    Then I load and and save like this:

    @#define SETTINGS_GENERAL_NICKNAME "general/nickname"
    #define SETTINGS_GENERAL_GENDER "general/gender"
    #define SETTINGS_GENERAL_AUTOAWAY "general/auto-away"
    #define SETTINGS_GENERAL_PUSHTOTALK "general/push-to-talk"
    #define SETTINGS_GENERAL_PUSHTOTALK_KEY "general/ptt-key"
    #define SETTINGS_GENERAL_VOICEACTIVATED "general/voice-activated"

    //save settings
    ttSettings->setValue(SETTINGS_GENERAL_NICKNAME, ui.nicknameEdit->text());
    ttSettings->setValue(SETTINGS_GENERAL_GENDER, ui.maleRadioButton->isChecked());
    ttSettings->setValue(SETTINGS_GENERAL_AUTOAWAY, ui.awaySpinBox->value());
    SaveHotKeySettings(HOTKEY_PUSHTOTALK, m_hotkey);
    ttSettings->setValue(SETTINGS_GENERAL_PUSHTOTALK, ui.pttChkBox->isChecked());
    ttSettings->setValue(SETTINGS_GENERAL_VOICEACTIVATED, ui.voiceactChkBox->isChecked());
    //...
    //load settings...
    ui.nicknameEdit->setText(ttSettings->value(SETTINGS_GENERAL_NICKNAME).toString());
    ui.maleRadioButton->setChecked(ttSettings->value(SETTINGS_GENERAL_GENDER, true).toBool());
    ui.femaleRadioButton->setChecked(!ttSettings->value(SETTINGS_GENERAL_GENDER, true).toBool());
    ui.awaySpinBox->setValue(ttSettings->value(SETTINGS_GENERAL_AUTOAWAY).toInt());
    ui.pttChkBox->setChecked(ttSettings->value(SETTINGS_GENERAL_PUSHTOTALK).toBool());@

    When I restart my application the settings I've saved before are not loaded again. It's like they've been reset. Anyone know what's going on?

    -- Bjoern

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

      Hi,

      Can you also provide which OS/Compiler you are using ?

      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
      • B Offline
        B Offline
        bear_dk
        wrote on last edited by
        #3

        I'm compiling on Mac OS X 10.6 x86_x64

        Here's the compiler version:
        @i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664)
        Copyright (C) 2007 Free Software Foundation, Inc.
        This is free software; see the source for copying conditions. There is NO
        warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.@
        Here's my command-line when compiling:
        @/Developer/usr/bin/g++ -c -pipe -g -gdwarf-2 -isysroot /Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.6 -Wall -W -fPIE -DQT_MULTIMEDIA_LIB -DQT_WIDGETS_LIB -DQT_NETWORK_LIB -DQT_XML_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../../../libraries/Qt5.2/mkspecs/macx-g++ -I. -I../TeamTalk_DLL -I../../../libraries/Qt5.2/lib/QtMultimedia.framework/Versions/5/Headers -I../../../libraries/Qt5.2/lib/QtWidgets.framework/Versions/5/Headers -I../../../libraries/Qt5.2/lib/QtNetwork.framework/Versions/5/Headers -I../../../libraries/Qt5.2/lib/QtXml.framework/Versions/5/Headers -I../../../libraries/Qt5.2/lib/QtGui.framework/Versions/5/Headers -I../../../libraries/Qt5.2/lib/QtCore.framework/Versions/5/Headers -I. -I/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers -I/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/AGL.framework/Headers -I. -F/Users/bdr/libraries/Qt5.2/lib -o moc_onlineusersdlg.o moc_onlineusersdlg.cpp@

        -- Bjoern

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

          Can you create a simple minimal example that reproduces this behavior ?

          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
          • S Offline
            S Offline
            ScottR
            wrote on last edited by
            #5

            "General" is a special section name reserved for keys set without section names specified.

            If you want something to go in the [General] section, you do not need to specify the text "general". So replace
            #define SETTINGS_GENERAL_NICKNAME "general/nickname"
            with
            #define SETTINGS_GENERAL_NICKNAME "nickname"

            , etc. Or use a section name other than "general".

            1 Reply Last reply
            0
            • B Offline
              B Offline
              bear_dk
              wrote on last edited by
              #6

              This seems to be something which has changed in Qt 5 because I've never seen this problem in Qt 4.

              -- Bjoern

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

                If you can setup a minimal compilable example that shows the behavior difference, then you should go on the "bug report system":http://bugreports.qt-project.org and check whether it's something known. If not open a new report providing the example

                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