'general' settings section works incorrectly
-
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
-
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
@Dmitriano
I know nothing, but is there an issue with your key being"general...and your file containing[%General...? -
@Dmitriano
I know nothing, but is there an issue with your key being"general...and your file containing[%General...? -
@JNBarchan Yes, it not clear enough what is the issue, but at least looks like something is wrong with QSettings.
@Dmitriano
I useQSettingsunder Linux but there is no%in the.inifile (all my sections/items start with uppercase though).... -
@Dmitriano
I useQSettingsunder Linux but there is no%in the.inifile (all my sections/items start with uppercase though).... -
@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
.inientry to[General]and and see if that resolves better. -
@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
.inientry to[General]and and see if that resolves better. -
@JNBarchan at least I did not name my section '%General'. Where to report 'General' section duplication as a bug?
-
Hi,
From a quicklook,
generalis a keyword used in the Qt sources inqsettings.cpp.