Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QSettings clear, what does it do?

Tags:

qt

qsettings

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

like image 466
Nyaruko Avatar asked May 26 '15 12:05

Nyaruko


People also ask

How does QSettings work?

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().

Where are QSettings stored on Mac?

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.


1 Answers

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.

Example

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.

like image 124
Flovdis Avatar answered Oct 29 '22 18:10

Flovdis