PDA

View Full Version : QSettings writes duplicate sections with strange names in ini-file



bear101
23rd December 2013, 11:13
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\xf f\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\x ff\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\x6 4\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