QtBase  v6.3.1
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
QSettings Class Reference

The QSettings class provides persistent platform-independent application settings. More...

#include <qsettings.h>

Inheritance diagram for QSettings:
Inheritance graph
[legend]
Collaboration diagram for QSettings:
Collaboration graph
[legend]

Public Types

enum  Status { NoError = 0 , AccessError , FormatError }
 
enum  Format {
  NativeFormat , IniFormat , InvalidFormat = 16 , CustomFormat1 ,
  CustomFormat2 , CustomFormat3 , CustomFormat4 , CustomFormat5 ,
  CustomFormat6 , CustomFormat7 , CustomFormat8 , CustomFormat9 ,
  CustomFormat10 , CustomFormat11 , CustomFormat12 , CustomFormat13 ,
  CustomFormat14 , CustomFormat15 , CustomFormat16
}
 
enum  Scope { UserScope , SystemScope }
 
typedef QMap< QString, QVariantSettingsMap
 
typedef bool(* ReadFunc) (QIODevice &device, SettingsMap &map)
 
typedef bool(* WriteFunc) (QIODevice &device, const SettingsMap &map)
 

Public Member Functions

 QSettings (const QString &organization, const QString &application=QString(), QObject *parent=nullptr)
 
 QSettings (Scope scope, const QString &organization, const QString &application=QString(), QObject *parent=nullptr)
 
 QSettings (Format format, Scope scope, const QString &organization, const QString &application=QString(), QObject *parent=nullptr)
 
 QSettings (const QString &fileName, Format format, QObject *parent=nullptr)
 
 QSettings (QObject *parent=nullptr)
 
 QSettings (Scope scope, QObject *parent=nullptr)
 
 ~QSettings ()
 
void clear ()
 
void sync ()
 
Status status () const
 
bool isAtomicSyncRequired () const
 
void setAtomicSyncRequired (bool enable)
 
void beginGroup (const QString &prefix)
 
void endGroup ()
 
QString group () const
 
int beginReadArray (const QString &prefix)
 
void beginWriteArray (const QString &prefix, int size=-1)
 
void endArray ()
 
void setArrayIndex (int i)
 
QStringList allKeys () const
 
QStringList childKeys () const
 
QStringList childGroups () const
 
bool isWritable () const
 
void setValue (const QString &key, const QVariant &value)
 
QVariant value (const QString &key, const QVariant &defaultValue) const
 
QVariant value (const QString &key) const
 
void remove (const QString &key)
 
bool contains (const QString &key) const
 
void setFallbacksEnabled (bool b)
 
bool fallbacksEnabled () const
 
QString fileName () const
 
Format format () const
 
Scope scope () const
 
QString organizationName () const
 
QString applicationName () const
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 
virtual ~QObject ()
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
QString objectName () const
 
void setObjectName (const QString &name)
 
QBindable< QStringbindableObjectName ()
 
bool isWidgetType () const
 
bool isWindowType () const
 
bool signalsBlocked () const noexcept
 
bool blockSignals (bool b) noexcept
 
QThreadthread () const
 
void moveToThread (QThread *thread)
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 
template<typename T >
T findChild (const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<typename T >
QList< TfindChildren (const QString &aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<typename T >
QList< TfindChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
const QObjectListchildren () const
 
void setParent (QObject *parent)
 
void installEventFilter (QObject *filterObj)
 
void removeEventFilter (QObject *obj)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const
 
bool disconnect (const QObject *receiver, const char *member=nullptr) const
 
void dumpObjectTree () const
 
void dumpObjectInfo () const
 
bool setProperty (const char *name, const QVariant &value)
 
QVariant property (const char *name) const
 
QList< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () const
 
bool inherits (const char *classname) const
 

Static Public Member Functions

static void setDefaultFormat (Format format)
 
static Format defaultFormat ()
 
static void setPath (Format format, Scope scope, const QString &path)
 
static Format registerFormat (const QString &extension, ReadFunc readFunc, WriteFunc writeFunc, Qt::CaseSensitivity caseSensitivity=Qt::CaseSensitive)
 
- Static Public Member Functions inherited from QObject
static QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 
static QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
static QMetaObject::Connection ::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 slot)
 
static QMetaObject::Connection ::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static std::enable_if< QtPrivate::FunctionPointer< Func2 >::ArgumentCount==-1 &&!std::is_convertible_v< Func2, const char * >, QMetaObject::Connection >::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 slot)
 
template<typename Func1 , typename Func2 >
static std::enable_if< QtPrivate::FunctionPointer< Func2 >::ArgumentCount==-1 &&!std::is_convertible_v< Func2, const char * >, QMetaObject::Connection >::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static bool disconnect (const QMetaObject::Connection &)
 
template<typename Func1 , typename Func2 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot)
 
template<typename Func1 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero)
 

Protected Member Functions

bool event (QEvent *event) override
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 
virtual void childEvent (QChildEvent *event)
 
virtual void customEvent (QEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
 QObject (QObjectPrivate &dd, QObject *parent=nullptr)
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 
- Signals inherited from QObject
void destroyed (QObject *=nullptr)
 
void objectNameChanged (const QString &objectName, QPrivateSignal)
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Properties inherited from QObject
QString objectName
 the name of this object More...
 

Detailed Description

The QSettings class provides persistent platform-independent application settings.

\inmodule QtCore

\reentrant

Users normally expect an application to remember its settings (window sizes and positions, options, etc.) across sessions. This information is often stored in the system registry on Windows, and in property list files on \macos and iOS. On Unix systems, in the absence of a standard, many applications (including the KDE applications) use INI text files.

QSettings is an abstraction around these technologies, enabling you to save and restore application settings in a portable manner. It also supports \l{registerFormat()}{custom storage formats}.

QSettings's API is based on QVariant, allowing you to save most value-based types, such as QString, QRect, and QImage, with the minimum of effort.

If all you need is a non-persistent memory-based structure, consider using QMap<QString, QVariant> instead.

section1

Definition at line 62 of file qsettings.h.

Member Typedef Documentation

◆ ReadFunc

QSettings::ReadFunc

Typedef for a pointer to a function with the following signature:

ReadFunc is used in registerFormat() as a pointer to a function that reads a set of key/value pairs. ReadFunc should read all the options in one pass, and return all the settings in the SettingsMap container, which is initially empty.

See also
WriteFunc, registerFormat()

Definition at line 186 of file qsettings.h.

◆ SettingsMap

Typedef for QMap<QString, QVariant>.

See also
registerFormat()

Definition at line 185 of file qsettings.h.

◆ WriteFunc

QSettings::WriteFunc

Typedef for a pointer to a function with the following signature:

WriteFunc is used in registerFormat() as a pointer to a function that writes a set of key/value pairs. WriteFunc is only called once, so you need to output the settings in one go.

See also
ReadFunc, registerFormat()

Definition at line 187 of file qsettings.h.

Member Enumeration Documentation

◆ Format

This enum type specifies the storage format used by QSettings.

\value NativeFormat Store the settings using the most appropriate storage format for the platform. On Windows, this means the system registry; on \macos and iOS, this means the CFPreferences API; on Unix, this means textual configuration files in INI format. \value Registry32Format Windows only: Explicitly access the 32-bit system registry from a 64-bit application running on 64-bit Windows. On 32-bit Windows or from a 32-bit application on 64-bit Windows, this works the same as specifying NativeFormat. This enum value was added in Qt 5.7. \value Registry64Format Windows only: Explicitly access the 64-bit system registry from a 32-bit application running on 64-bit Windows. On 32-bit Windows or from a 64-bit application on 64-bit Windows, this works the same as specifying NativeFormat. This enum value was added in Qt 5.7. \value IniFormat Store the settings in INI files. Note that INI files lose the distinction between numeric data and the strings used to encode them, so values written as numbers shall be read back as QString.

\value InvalidFormat Special value returned by registerFormat(). \omitvalue CustomFormat1 \omitvalue CustomFormat2 \omitvalue CustomFormat3 \omitvalue CustomFormat4 \omitvalue CustomFormat5 \omitvalue CustomFormat6 \omitvalue CustomFormat7 \omitvalue CustomFormat8 \omitvalue CustomFormat9 \omitvalue CustomFormat10 \omitvalue CustomFormat11 \omitvalue CustomFormat12 \omitvalue CustomFormat13 \omitvalue CustomFormat14 \omitvalue CustomFormat15 \omitvalue CustomFormat16

On Unix, NativeFormat and IniFormat mean the same thing, except that the file extension is different (.conf for NativeFormat, .ini for IniFormat).

The INI file format is a Windows file format that Qt supports on all platforms. In the absence of an INI standard, we try to follow what Microsoft does, with the following exceptions:

\list

Enumerator
NativeFormat 
IniFormat 
InvalidFormat 
CustomFormat1 
CustomFormat2 
CustomFormat3 
CustomFormat4 
CustomFormat5 
CustomFormat6 
CustomFormat7 
CustomFormat8 
CustomFormat9 
CustomFormat10 
CustomFormat11 
CustomFormat12 
CustomFormat13 
CustomFormat14 
CustomFormat15 
CustomFormat16 

Definition at line 84 of file qsettings.h.

◆ Scope

) in file paths:

QSettings always treats backslash as a special character and provides no API for reading or writing such entries.

  • The INI file format has severe restrictions on the syntax of a key. Qt works around this by using % as an escape character in keys. In addition, if you save a top-level setting (a key with no slashes in it, e.g., "someKey"), it will appear in the INI file's "General" section. To avoid overwriting other keys, if you save something using a key such as "General/someKey", the key will be located in the "%General" section, not in the "General" section.
  • In line with most implementations today, QSettings will assume the INI file is utf-8 encoded. This means that keys and values will be decoded as utf-8 encoded entries and written back as utf-8.

\endlist

Enumerator
UserScope 
SystemScope 

Definition at line 115 of file qsettings.h.

◆ Status

The following status values are possible:

\value NoError No error occurred. \value AccessError An access error occurred (e.g. trying to write to a read-only file). \value FormatError A format error occurred (e.g. loading a malformed INI file).

See also
status()
Enumerator
NoError 
AccessError 
FormatError 

Definition at line 75 of file qsettings.h.

Constructor & Destructor Documentation

◆ QSettings() [1/6]

QSettings::QSettings ( const QString organization,
const QString application = QString(),
QObject parent = nullptr 
)
explicit

Constructs a QSettings object for accessing settings of the application called application from the organization called organization, and with parent parent.

Example:

The scope is set to QSettings::UserScope, and the format is set to QSettings::NativeFormat (i.e. calling setDefaultFormat() before calling this constructor has no effect).

See also
setDefaultFormat(), {Fallback Mechanism}

Definition at line 2482 of file qsettings.cpp.

◆ QSettings() [2/6]

QSettings::QSettings ( Scope  scope,
const QString organization,
const QString application = QString(),
QObject parent = nullptr 
)

Constructs a QSettings object for accessing settings of the application called application from the organization called organization, and with parent parent.

If scope is QSettings::UserScope, the QSettings object searches user-specific settings first, before it searches system-wide settings as a fallback. If scope is QSettings::SystemScope, the QSettings object ignores user-specific settings and provides access to system-wide settings.

The storage format is set to QSettings::NativeFormat (i.e. calling setDefaultFormat() before calling this constructor has no effect).

If no application name is given, the QSettings object will only access the organization-wide \l{Fallback Mechanism}{locations}.

See also
setDefaultFormat()

Definition at line 2507 of file qsettings.cpp.

◆ QSettings() [3/6]

QSettings::QSettings ( Format  format,
Scope  scope,
const QString organization,
const QString application = QString(),
QObject parent = nullptr 
)

Constructs a QSettings object for accessing settings of the application called application from the organization called organization, and with parent parent.

If scope is QSettings::UserScope, the QSettings object searches user-specific settings first, before it searches system-wide settings as a fallback. If scope is QSettings::SystemScope, the QSettings object ignores user-specific settings and provides access to system-wide settings.

If format is QSettings::NativeFormat, the native API is used for storing settings. If format is QSettings::IniFormat, the INI format is used.

If no application name is given, the QSettings object will only access the organization-wide \l{Fallback Mechanism}{locations}.

Definition at line 2531 of file qsettings.cpp.

◆ QSettings() [4/6]

QSettings::QSettings ( const QString fileName,
Format  format,
QObject parent = nullptr 
)

Constructs a QSettings object for accessing the settings stored in the file called fileName, with parent parent. If the file doesn't already exist, it is created.

If format is QSettings::NativeFormat, the meaning of fileName depends on the platform. On Unix, fileName is the name of an INI file. On \macos and iOS, fileName is the name of a .plist file. On Windows, fileName is a path in the system registry.

If format is QSettings::IniFormat, fileName is the name of an INI file.

Warning
This function is provided for convenience. It works well for accessing INI or .plist files generated by Qt, but might fail on some syntaxes found in such files originated by other programs. In particular, be aware of the following limitations:

\list

  • QSettings provides no way of reading INI "path" entries, i.e., entries with unescaped slash characters. (This is because these entries are ambiguous and cannot be resolved automatically.)
  • In INI files, QSettings uses the @ character as a metacharacter in some contexts, to encode Qt-specific data types (e.g., @Rect ), and might therefore misinterpret it when it occurs in pure INI files. \endlist
See also
fileName()

Definition at line 2567 of file qsettings.cpp.

◆ QSettings() [5/6]

QSettings::QSettings ( QObject parent = nullptr)
explicit

Constructs a QSettings object for accessing settings of the application and organization set previously with a call to QCoreApplication::setOrganizationName(), QCoreApplication::setOrganizationDomain(), and QCoreApplication::setApplicationName().

The scope is QSettings::UserScope and the format is defaultFormat() (QSettings::NativeFormat by default). Use setDefaultFormat() before calling this constructor to change the default format used by this constructor.

The code

is equivalent to

If QCoreApplication::setOrganizationName() and QCoreApplication::setApplicationName() has not been previously called, the QSettings object will not be able to read or write any settings, and status() will return AccessError.

You should supply both the domain (used by default on \macos and iOS) and the name (used by default elsewhere), although the code will cope if you supply only one, which will then be used (on all platforms), at odds with the usual naming of the file on platforms for which it isn't the default.

See also
QCoreApplication::setOrganizationName(), QCoreApplication::setOrganizationDomain(), QCoreApplication::setApplicationName(), setDefaultFormat()

Definition at line 2607 of file qsettings.cpp.

◆ QSettings() [6/6]

QSettings::QSettings ( Scope  scope,
QObject parent = nullptr 
)
explicit
Since
5.13

Constructs a QSettings object in the same way as QSettings(QObject *parent) but with the given scope.

See also
QSettings(QObject *parent)

Definition at line 2620 of file qsettings.cpp.

◆ ~QSettings()

QSettings::~QSettings ( )

Destroys the QSettings object.

Any unsaved changes will eventually be written to permanent storage.

See also
sync()

Definition at line 2688 of file qsettings.cpp.

Member Function Documentation

◆ allKeys()

QStringList QSettings::allKeys ( ) const

Returns a list of all keys, including subkeys, that can be read using the QSettings object.

Example:

If a group is set using beginGroup(), only the keys in the group are returned, without the group prefix:

See also
childGroups(), childKeys()

Definition at line 3057 of file qsettings.cpp.

◆ applicationName()

QString QSettings::applicationName ( ) const
Since
4.4

Returns the application name used for storing the settings.

See also
QCoreApplication::applicationName(), format(), scope(), organizationName()

Definition at line 2798 of file qsettings.cpp.

◆ beginGroup()

void QSettings::beginGroup ( const QString prefix)

Appends prefix to the current group.

The current group is automatically prepended to all keys specified to QSettings. In addition, query functions such as childGroups(), childKeys(), and allKeys() are based on the group. By default, no group is set.

Groups are useful to avoid typing in the same setting paths over and over. For example:

This will set the value of three settings:

\list

  • mainwindow/size
  • mainwindow/fullScreen
  • outputpanel/visible \endlist

Call endGroup() to reset the current group to what it was before the corresponding beginGroup() call. Groups can be nested.

See also
endGroup(), group()

Definition at line 2890 of file qsettings.cpp.

◆ beginReadArray()

int QSettings::beginReadArray ( const QString prefix)

Adds prefix to the current group and starts reading from an array. Returns the size of the array.

Example:

Use beginWriteArray() to write the array in the first place.

See also
beginWriteArray(), endArray(), setArrayIndex()

Definition at line 2946 of file qsettings.cpp.

Here is the call graph for this function:

◆ beginWriteArray()

void QSettings::beginWriteArray ( const QString prefix,
int  size = -1 
)

Adds prefix to the current group and starts writing an array of size size. If size is -1 (the default), it is automatically determined based on the indexes of the entries written.

If you have many occurrences of a certain set of keys, you can use arrays to make your life easier. For example, let's suppose that you want to save a variable-length list of user names and passwords. You could then write:

The generated keys will have the form

\list

  • logins/size
  • logins/1/userName
  • logins/1/password
  • logins/2/userName
  • logins/2/password
  • logins/3/userName
  • logins/3/password
  • ... \endlist

To read back an array, use beginReadArray().

See also
beginReadArray(), endArray(), setArrayIndex()

Definition at line 2982 of file qsettings.cpp.

Here is the call graph for this function:

◆ childGroups()

QStringList QSettings::childGroups ( ) const

Returns a list of all key top-level groups that contain keys that can be read using the QSettings object.

Example:

If a group is set using beginGroup(), the first-level keys in that group are returned, without the group prefix.

You can navigate through the entire setting hierarchy using childKeys() and childGroups() recursively.

See also
childKeys(), allKeys()

Definition at line 3105 of file qsettings.cpp.

◆ childKeys()

QStringList QSettings::childKeys ( ) const

Returns a list of all top-level keys that can be read using the QSettings object.

Example:

If a group is set using beginGroup(), the top-level keys in that group are returned, without the group prefix:

You can navigate through the entire setting hierarchy using childKeys() and childGroups() recursively.

See also
childGroups(), allKeys()

Definition at line 3081 of file qsettings.cpp.

Here is the caller graph for this function:

◆ clear()

void QSettings::clear ( )

Removes all entries in the primary location associated to this QSettings object.

Entries in fallback locations are not removed.

If you only want to remove the entries in the current group(), use remove("") instead.

See also
remove(), setFallbacksEnabled()

Definition at line 2712 of file qsettings.cpp.

◆ contains()

bool QSettings::contains ( const QString key) const

Returns true if there exists a setting called key; returns false otherwise.

If a group is set using beginGroup(), key is taken to be relative to that group.

Note that the Windows registry and INI files use case-insensitive keys, whereas the CFPreferences API on \macos and iOS uses case-sensitive keys. To avoid portability problems, see the \l{Section and Key Syntax} rules.

See also
value(), setValue()

Definition at line 3214 of file qsettings.cpp.

Here is the caller graph for this function:

◆ defaultFormat()

QSettings::Format QSettings::defaultFormat ( )
static
Since
4.4

Returns default file format used for storing settings for the QSettings(QObject *) constructor. If no default format is set, QSettings::NativeFormat is used.

See also
format()

Definition at line 3332 of file qsettings.cpp.

◆ endArray()

void QSettings::endArray ( )

Closes the array that was started using beginReadArray() or beginWriteArray().

See also
beginReadArray(), beginWriteArray()

Definition at line 2999 of file qsettings.cpp.

Here is the call graph for this function:

◆ endGroup()

void QSettings::endGroup ( )

Resets the group to what it was before the corresponding beginGroup() call.

Example:

See also
beginGroup(), group()

Definition at line 2906 of file qsettings.cpp.

◆ event()

bool QSettings::event ( QEvent event)
overrideprotectedvirtual

\reimp

Reimplemented from QObject.

Definition at line 3250 of file qsettings.cpp.

Here is the call graph for this function:

◆ fallbacksEnabled()

bool QSettings::fallbacksEnabled ( ) const

Returns true if fallbacks are enabled; returns false otherwise.

By default, fallbacks are enabled.

See also
setFallbacksEnabled()

Definition at line 3240 of file qsettings.cpp.

◆ fileName()

QString QSettings::fileName ( ) const

Returns the path where settings written using this QSettings object are stored.

On Windows, if the format is QSettings::NativeFormat, the return value is a system registry path, not a file path.

See also
isWritable(), format()

Definition at line 2746 of file qsettings.cpp.

◆ format()

QSettings::Format QSettings::format ( ) const
Since
4.4

Returns the format used for storing the settings.

See also
defaultFormat(), fileName(), scope(), organizationName(), applicationName()

Definition at line 2759 of file qsettings.cpp.

◆ group()

QString QSettings::group ( ) const

Returns the current group.

See also
beginGroup(), endGroup()

Definition at line 2928 of file qsettings.cpp.

Here is the caller graph for this function:

◆ isAtomicSyncRequired()

bool QSettings::isAtomicSyncRequired ( ) const
Since
5.10

Returns true if QSettings is only allowed to perform atomic saving and reloading (synchronization) of the settings. Returns false if it is allowed to save the settings contents directly to the configuration file.

The default is true.

See also
setAtomicSyncRequired(), QSaveFile

Definition at line 2831 of file qsettings.cpp.

◆ isWritable()

bool QSettings::isWritable ( ) const

Returns true if settings can be written using this QSettings object; returns false otherwise.

One reason why isWritable() might return false is if QSettings operates on a read-only file.

Warning
This function is not perfectly reliable, because the file permissions can change at any time.
See also
fileName(), status(), sync()

Definition at line 3123 of file qsettings.cpp.

Here is the caller graph for this function:

◆ organizationName()

QString QSettings::organizationName ( ) const
Since
4.4

Returns the organization name used for storing the settings.

See also
QCoreApplication::organizationName(), format(), scope(), applicationName()

Definition at line 2785 of file qsettings.cpp.

◆ registerFormat()

QSettings::Format QSettings::registerFormat ( const QString extension,
ReadFunc  readFunc,
WriteFunc  writeFunc,
Qt::CaseSensitivity  caseSensitivity = Qt::CaseSensitive 
)
static
Since
4.1 \threadsafe

Registers a custom storage format. On success, returns a special Format value that can then be passed to the QSettings constructor. On failure, returns InvalidFormat.

The extension is the file extension associated to the format (without the '.').

The readFunc and writeFunc parameters are pointers to functions that read and write a set of key/value pairs. The QIODevice parameter to the read and write functions is always opened in binary mode (i.e., without the QIODevice::Text flag).

The caseSensitivity parameter specifies whether keys are case sensitive or not. This makes a difference when looking up values using QSettings. The default is case sensitive.

By default, if you use one of the constructors that work in terms of an organization name and an application name, the file system locations used are the same as for IniFormat. Use setPath() to specify other locations.

Example:

See also
setPath()

Definition at line 3448 of file qsettings.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove()

void QSettings::remove ( const QString key)

Removes the setting key and any sub-settings of key.

Example:

Be aware that if one of the fallback locations contains a setting with the same key, that setting will be visible after calling remove().

If key is an empty string, all keys in the current group() are removed. For example:

Note that the Windows registry and INI files use case-insensitive keys, whereas the CFPreferences API on \macos and iOS uses case-sensitive keys. To avoid portability problems, see the \l{Section and Key Syntax} rules.

See also
setValue(), value(), contains()

Definition at line 3179 of file qsettings.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scope()

QSettings::Scope QSettings::scope ( ) const
Since
4.4

Returns the scope used for storing the settings.

See also
format(), organizationName(), applicationName()

Definition at line 2772 of file qsettings.cpp.

◆ setArrayIndex()

void QSettings::setArrayIndex ( int  i)

Sets the current array index to i. Calls to functions such as setValue(), value(), remove(), and contains() will operate on the array entry at that index.

You must call beginReadArray() or beginWriteArray() before you can call this function.

Definition at line 3028 of file qsettings.cpp.

Here is the caller graph for this function:

◆ setAtomicSyncRequired()

void QSettings::setAtomicSyncRequired ( bool  enable)
Since
5.10

Configures whether QSettings is required to perform atomic saving and reloading (synchronization) of the settings. If the enable argument is true (the default), sync() will only perform synchronization operations that are atomic. If this is not possible, sync() will fail and status() will be an error condition.

Setting this property to false will allow QSettings to write directly to the configuration file and ignore any errors trying to lock it against other processes trying to write at the same time. Because of the potential for corruption, this option should be used with care, but is required in certain conditions, like a QSettings::IniFormat configuration file that exists in an otherwise non-writeable directory or NTFS Alternate Data Streams.

See \l QSaveFile for more information on the feature.

See also
isAtomicSyncRequired(), QSaveFile

Definition at line 2858 of file qsettings.cpp.

◆ setDefaultFormat()

void QSettings::setDefaultFormat ( Format  format)
static
Since
4.4

Sets the default file format to the given format, which is used for storing settings for the QSettings(QObject *) constructor.

If no default format is set, QSettings::NativeFormat is used. See the documentation for the QSettings constructor you are using to see if that constructor will ignore this function.

See also
format()

Definition at line 3319 of file qsettings.cpp.

◆ setFallbacksEnabled()

void QSettings::setFallbacksEnabled ( bool  b)

Sets whether fallbacks are enabled to b.

By default, fallbacks are enabled.

See also
fallbacksEnabled()

Definition at line 3227 of file qsettings.cpp.

Here is the caller graph for this function:

◆ setPath()

void QSettings::setPath ( Format  format,
Scope  scope,
const QString path 
)
static
Since
4.1

Sets the path used for storing settings for the given format and scope, to path. The format can be a custom format.

The table below summarizes the default values:

\table \header

  • Platform
  • Format
  • Scope
  • Path \row
  • {1,2} Windows
  • {1,2} IniFormat
  • UserScope
  • FOLDERID_RoamingAppData \row
  • SystemScope
  • FOLDERID_ProgramData \row
  • {1,2} Unix
  • {1,2} NativeFormat, IniFormat
  • UserScope
  • $HOME/.config \row
  • SystemScope
  • /etc/xdg \row
  • {1,2} Qt for Embedded Linux
  • {1,2} NativeFormat, IniFormat
  • UserScope
  • $HOME/Settings \row
  • SystemScope
  • /etc/xdg \row
  • {1,2} \macos and iOS
  • {1,2} IniFormat
  • UserScope
  • $HOME/.config \row
  • SystemScope
  • /etc/xdg \endtable

The default UserScope paths on Unix, \macos, and iOS ($HOME/.config or $HOME/Settings) can be overridden by the user by setting the XDG_CONFIG_HOME environment variable. The default SystemScope paths on Unix, \macos, and iOS (/etc/xdg) can be overridden when building the Qt library using the configure script's -sysconfdir flag (see QLibraryInfo for details).

Setting the NativeFormat paths on Windows, \macos, and iOS has no effect.

Warning
This function doesn't affect existing QSettings objects.
See also
registerFormat()

Definition at line 3371 of file qsettings.cpp.

Here is the call graph for this function:

◆ setValue()

void QSettings::setValue ( const QString key,
const QVariant value 
)

Sets the value of setting key to value. If the key already exists, the previous value is overwritten.

Note that the Windows registry and INI files use case-insensitive keys, whereas the CFPreferences API on \macos and iOS uses case-sensitive keys. To avoid portability problems, see the \l{Section and Key Syntax} rules.

Example:

See also
value(), remove(), contains()

Definition at line 3145 of file qsettings.cpp.

Here is the caller graph for this function:

◆ status()

QSettings::Status QSettings::status ( ) const

Returns a status code indicating the first error that was met by QSettings, or QSettings::NoError if no error occurred.

Be aware that QSettings delays performing some operations. For this reason, you might want to call sync() to ensure that the data stored in QSettings is written to disk before calling status().

See also
sync()

Definition at line 2814 of file qsettings.cpp.

Here is the caller graph for this function:

◆ sync()

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.

See also
status()

Definition at line 2730 of file qsettings.cpp.

Here is the caller graph for this function:

◆ value() [1/2]

QVariant QSettings::value ( const QString key) const

Definition at line 3282 of file qsettings.cpp.

Here is the caller graph for this function:

◆ value() [2/2]

QVariant QSettings::value ( const QString key,
const QVariant defaultValue 
) const

Returns the value for setting key. If the setting doesn't exist, returns defaultValue.

If no default value is specified, a default QVariant is returned.

Note that the Windows registry and INI files use case-insensitive keys, whereas the CFPreferences API on \macos and iOS uses case-sensitive keys. To avoid portability problems, see the \l{Section and Key Syntax} rules.

Example:

See also
setValue(), contains(), remove()

Definition at line 3288 of file qsettings.cpp.

Here is the caller graph for this function:

The documentation for this class was generated from the following files: