The doc said about the QSettings::clear
function as:
Removes all entries in the primary location associated to this QSettings object.
Entries in fallback locations are not removed.
But what does this mean? what's the primary location and fall back location???
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. To write a setting, use setValue().
Bookmark this question. Show activity on this post. According to Qt's docs for the latest Qt version, looking at QSettings, they say that system scope of settings on a Mac are stored in a directory /etc/xdg.
The primary location depends on the OS and your settings. For Windows this is the registry, etc. From the documentation of QSettings
:
Let's assume that you have created a QSettings object with the organization name MySoft and the application name Star Runner. When you look up a value, up to four locations are searched in that order:
- a user-specific location for the Star Runner application
- a user-specific location for all applications by MySoft
- a system-wide location for the Star Runner application
- a system-wide location for all applications by MySoft
The primary location is the most specific one: usually an user-specific location for your application.
You can provide shared default values for all users/applications. But they are not deleted if you call clear()
. Just the user and application specific values are cleared.
If you initialise the QSettings
object with the company and application name or using the default constructor, the primary values are the application and user specific values. This the the case for most applications. If you just create an QSettings
object using the default constructor, the values from QApplication
(application name, and organization name) are used.
QSettings settings("MySoft", "Star Runner");
settings.clear();
// or
QSettings settings(); // use the values from QApplication
settings.clear();
If you initialize the QSettings
object with other values, you can choose another primary "store":
QSettings settings("MySoft");
settings.clear(); // clears values for whole company if possible.
QSettings settings(QSettings::SystemScope, "MySoft", "Star Runner");
settings.clear(); // clears system wide settings for the application.
QSettings settings(QSettings::SystemScope, "MySoft");
settings.clear(); // clears system wide settings for the company.
This last three cases are rare and make not much sense. Also the application needs the permission to write to the system wide settings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With