Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qsettings Erratic Behaviour

Qsettings Erratic Behaviour

Scheduled Pinned Locked Moved Solved General and Desktop
qsettingsqdebug
3 Posts 2 Posters 557 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    markd
    wrote on last edited by
    #1

    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?

    jsulmJ 1 Reply Last reply
    0
    • M markd

      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?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • M Offline
        M Offline
        markd
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved