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. Erratic QSettings behavior
Forum Updated to NodeBB v4.3 + New Features

Erratic QSettings behavior

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 149 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.
  • vikramgV Offline
    vikramgV Offline
    vikramg
    wrote on last edited by vikramg
    #1

    I am seeing really perplexing behavior from QSettings in an application where I am accessing the settings both in C++ and in QML. The QSettings QML type documentation doesn't say anything about concurrent access via the Settings type in QML and QSettings in C++, although the QSettings documentation explicitly says that it is thread safe.

    The expectation was that if I update settings from QML, it should be visible from any thread in C++, and vice versa.

    But I am unable to even get QSettings to be consistent between C++ and QML in the main thread. In all the cases below, I am using the default Settings object that creates a conf file under $HOME/.config/Org/AppName.conf. What I see is:

    • If I update settings in C++, it is visible in all threads in C++. However - conf file does not get updated, (even if I call sync() on the object) and new settings are not visible from QML either. [There is one older post on other erratic behavior in QSettings but the OP's problem seemed to get resolved after using sync].
    • If I update settings in QML, conf file gets updated immediately, but updated settings are not visible in C++.

    However, sometimes the update from C++ does work (conf file does get updated - although I didn't check at the time if QML saw it). The only way to ensure both sides (C++ and QML) as well as the conf file all stay consistent is to always do the same update to Settings from QML and C++. This seems like a pretty hacky solution however. Is there something I am missing in how to use QSettings? Is it not guaranteed to work consistently across QML and C++?

    Qt 5.12 on x86-64 Ubuntu 20.04.

    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