QSettings writes duplicate sections with strange names in ini-file



  • 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


  • Lifetime Qt Champion

    Hi,

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



  • 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


  • Lifetime Qt Champion

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



  • "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".



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

    -- Bjoern


  • Lifetime Qt Champion

    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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.