qt settings file issue
-
Hi,
I found an possible issue with QSettings:
Here are the part from my code:QSettings settings(settingsFile, QSettings::IniFormat); rgbProfile = QString(settings.value("cmm/profile_rgb", "ProPhoto.icm").toString()).toStdString();
I would expect, that if the entry "cmm/profile_rgb" is empty or missing I get "ProPhoto.icm" as default value.
But this happens only if the entry is fully missing!
If the entry ist there but empty like this - I get an empty value for rgbProfile:[cmm] profile_rgb=
Is there an option to change behavior of QSettings or can you confirm this a bug?
thx and regards
Alex -
Ini format is not very well defined and behaviors differ a lot between different parsers, especially when it comes to white space treatment.
Having said that I wouldn't consider this a bug. The default parameter is only used when the key is not found. If it is the value is considered present, even if it's an empty one. An empty value can be a useful thing. For example it can be used to store empty strings, which in some cases can be a valid value for a key and shouldn't be replaced by defaults.
As far as I know there's no built in mechanism to change that behavior of QSettings ini parsing, so just add an extra check for the empty values if you want it that way.
-
I would concur with @Chris-Kawa in that it's not a bug or a "bad behaviour". The key exists and has a null value. That is a case worth checking for. Simply absorb the overhead of comparing the result against a null string and react accordingly.