From the Qt help function:
void QSettings::sync() Writes any unsaved changes to permanent storage, and reloads any settings that have been changed in the meantime by another application. This function is called automatically from QSettings's destructor and by the event loop at regular intervals, so you normally don't need to call it yourself.
What exactly does "meantime" mean here? Does this always reset my settings to the point when I started my program, meaning I can never change my config during its runtime when using sync()?
You can suppose that the QSettings is implemented as a global std::map<QString, QVariant>
that acts like the cache of the settings. The documentation says:
QSettings stores settings. Each setting consists of a QString that specifies the setting's name (the key) and a QVariant that stores the data associated with the key.
For efficiency reason, the documentation says:
For efficiency, the changes may not be saved to permanent storage immediately. (You can always call sync() to commit your changes.)
Each time, you modify a setting the cache value is updated but not the persistent file. The behavior of QSettings depends on the platform.
If you want to know how frequently does it store/refresh the file located in the hard-drive, you need to know where it's located.
You can retrieve the path using the QStandardPaths class and the QStandardPaths::ConfigLocation
tag:
qDebug() << QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
To track the modifications in the file (how frequently the sync functions is performed), you can use this python script.
Answering your question: ? Does this always reset my settings to the point when I started my program, meaning I can never change my config during its runtime when using sync()?
QSettings::sync
merges the modifications from the system file and the ones in your cache to store it in the file. If you have several applications modifying the same file, they may overwrite each other.
In your case, if you are using QSettings
to save the data of your own app, it won't restore anything to the original state. It will always write your modifications in to the file and keep the cache up to date.