Qsettings Erratic Behaviour
-
wrote on 10 Dec 2019, 21:41 last edited by
I am getting erratic behaviour when retrieving saved parameters using Qsettings. Most of the time everything works as it should but occasionally values are returned as 0.0, without any other indication that anything is wrong. I haven't been able to reproduce the behaviour consistently but it seems to be related to heavy use of qDebug() statements.
I'm using Qt 5.9.1 on Ubuntu 16.04.
Relevant code fragments are below:
QCoreApplication::setOrganizationName("xxx Technologies"); QCoreApplication::setOrganizationDomain("xxxT.com"); QCoreApplication::setApplicationName("yyy"); QSettings settings; if (settings.value("Camera/FrameRate").isNull()) { settings.setValue("Camera/FrameRate",4); } frameRate = settings.value("Camera/FrameRate").toDouble();
Most of the time frameRate is read back correctly as a value greater than 0 but sometimes it is returned as 0.0.
We have noticed the same behaviour with other saved values as well.
Any ideas what I might be doing wrong or ways to verify that the file is actually there and ready before I try to read the value?
-
I am getting erratic behaviour when retrieving saved parameters using Qsettings. Most of the time everything works as it should but occasionally values are returned as 0.0, without any other indication that anything is wrong. I haven't been able to reproduce the behaviour consistently but it seems to be related to heavy use of qDebug() statements.
I'm using Qt 5.9.1 on Ubuntu 16.04.
Relevant code fragments are below:
QCoreApplication::setOrganizationName("xxx Technologies"); QCoreApplication::setOrganizationDomain("xxxT.com"); QCoreApplication::setApplicationName("yyy"); QSettings settings; if (settings.value("Camera/FrameRate").isNull()) { settings.setValue("Camera/FrameRate",4); } frameRate = settings.value("Camera/FrameRate").toDouble();
Most of the time frameRate is read back correctly as a value greater than 0 but sometimes it is returned as 0.0.
We have noticed the same behaviour with other saved values as well.
Any ideas what I might be doing wrong or ways to verify that the file is actually there and ready before I try to read the value?
@markd What you could do: when you read the settings read the whole settings file as string and print it out to see how the file content looks like. Just to verify that the stored value is indeed not 0.0
-
wrote on 12 Mar 2020, 17:41 last edited by
Qsettings documentation says it is reentrant and thread-safe but since I have started adding .sync() between writing and reading, I have not seen the problem.