Solved '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
-
@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 useQSettings
under Linux but there is no%
in the.ini
file (all my sections/items start with uppercase though).... -
@JNBarchan did you try 'general' section? Probably it is a special case.
-
@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. -
@JNBarchan at least I did not name my section '%General'. Where to report 'General' section duplication as a bug?
-
-
@jsulm reported this as a bug here https://bugreports.qt.io/browse/QTBUG-63694
-
Hi,
From a quicklook,
general
is a keyword used in the Qt sources inqsettings.cpp
.