Qt5 QSettings works wrong ?
-
Hi
As I was trying to load some settings from ini file into my application tests (no QApplication object is present)
I spotted possible error.@ QSettings settings(fileName, QSettings::IniFormat);
settings.beginGroup("group");
_key1 = settings.value("key1").toString();
_key2 = settings.value("key2").toString();
settings.endGroup();@Code above resulted in all variables being empty. So I tweaked code a little to check whether file is missing or invalid.
@ QSettings settings(fileName, QSettings::IniFormat);
settings.allKeys();
settings.beginGroup("group");
_key1 = settings.value("key1").toString();
_key2 = settings.value("key2").toString();
settings.endGroup();@After adding call to allKeys all variables was loaded properly (sync does not worked).
This workaround looks creepy. For me the most intuitive way to process ini file is to do it in constructor.
My question is whether this is some undocumented feature or simple bug? -
Hi,
to use correctly Qt you MUST use QCoreApplication or one of inherited.
QSettings uses it to access to standard PATH and so on.bq. void QSettings::sync()
Writes any unsaved changes to permanent storage, and reloads any settings that have been changed in the meantime by another application.
This function is called automatically from QSettings's destructor and by the event loop at regular intervals, so you normally don't need to call it yourself.If you don't have a Q*Application you don't have eventLoop.