Important: Please read the Qt Code of Conduct -

Qsettings Erratic Behaviour

  • 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");
    QSettings settings;
    if (settings.value("Camera/FrameRate").isNull()) {
    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?

  • Qt Champions 2019

    @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

  • 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.

Log in to reply