Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QSettings for Qt 4.7 TI embedded issue
Forum Updated to NodeBB v4.3 + New Features

QSettings for Qt 4.7 TI embedded issue

Scheduled Pinned Locked Moved Mobile and Embedded
6 Posts 2 Posters 1.4k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    Alexander87
    wrote on last edited by
    #1

    Hi there!

    So my problem is that sometimes when i write value to qsettings then tries to get it later, it seems like the value wasn't saved. This seems to happen pretty randomly.

    Some background:
    I use three different application. Each application reads from the same qsetting file, but with different groups, every second. The applications communicates with each other using qsettings by changing each other values for their representive group. However sometimes it seems like when I write from one application, the other application doesn't get the correct value (or it's not written at all).

    I'm using the following shared code between the three applications:
    @template <class T> const T getSharedResources(const QString group, const QString key)
    {
    QSettings settings(QSettings::NativeFormat,QSettings::UserScope ,"Company", "sharedResources");
    sync();
    settings.sync();
    settings.beginGroup(group);
    T value;
    if(settings.contains(key)) {
    value = settings.value(key).value<T>();
    }
    settings.endGroup();
    qDebug() << FUNCTION << group << " " << key << " " << value; return value;
    }

    template <class T> void setSharedResources(const QString group, const QString key, const T value)
    {
    qDebug() << FUNCTION << group << " " << key << " " << value;
    QSettings settings(QSettings::NativeFormat,QSettings::UserScope ,"Company", "sharedResources");
    settings.beginGroup(group);
    settings.setValue(key,value);
    settings.endGroup();
    settings.sync();
    sync();
    qDebug() << FUNCTION << settings.status() << getSharedResources<T>(group,key);
    }@

    At the end of setting the qsettings I double check what value was written by using the getsharedresources method.

    The output goes like this:

    setSharedResources "Slot" "Application1" 2
    setSharedResources 0 2
    getSharedResources "Slot" "Application1" 1

    How come it changed from output line 2 to line 3? setSharedResources is not called between those lines? Also this is not a bug which happens always, maybe 50/50.

    What could the problem be? Let me know if something is unclear

    / Alex

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Depending on the OS and format used, QSettings value may not necessarily flush the data on disc right away (e.g. OS caching, VFS caching, hard drive spinning etc..)

      If all your applications communicate with each other, you should maybe consider a real IPC mechanism e.g. QSharedMemory, QLocalServer/Socket etc…

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Alexander87
        wrote on last edited by
        #3

        Hi, thank you=) and thank you for your reply!

        I use linux embedded on a TI arm processor. It doesn't need to be flushed right away since the applications are looking for changes every second. Also it seems weird that it changes the qsetting value at first (refers to output in my first post) then puts it back. I've waited several minutes but it seems like the value is not changed according to what has been written. However when it do work it is immediately.

        I've tried using QCOP as well as D-BUS which didn't really work because of how the applications are running. One is used as a watchdog monitoring if the two other applications works as they should (if they don't I'm providing GUI content, so this one is a GUIClient). One is used as background Video layer linked to one framebuffer and the last one is the GUI linked to a second framebuffer overlaying the first.

        Will QSharedMemory work better?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          After some more thoughts I see what pitfall you got into. Each of your program reads the settings file, update some value then write it back. The writing action updates the entire file, not just the section your modified thus you end up having a value updated by one process then replaced by the old value from the other process.

          You should test/compare the different IPC mechanism to see which one fits best your architecture

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Alexander87
            wrote on last edited by
            #5

            Ah, you are right!

            So basically one solution would be to dived it into three different settings for each application (since I only write to one application at a time).

            However I believe a real IPC is probably a more elegant and safe solution.

            Thank you for the support!

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Again, it depends whether several process are writing to it. I you only have one writer for one reader, then go on. Otherwise, you're looking for trouble

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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