Erratic QSettings behavior
-
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 usingsync
]. - 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.
- 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