Important: Please read the Qt Code of Conduct -

QSettings for Qt 4.7 TI embedded issue

  • 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");
    T value;
    if(settings.contains(key)) {
    value = settings.value(key).value<T>();
    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");
    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

  • Lifetime Qt Champion

    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

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

  • Lifetime Qt Champion

    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

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

  • Lifetime Qt Champion

    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

Log in to reply