![]() |
Qt 6.x
The Qt SDK
|
\inmodule QtCore More...
#include <qsettings.h>
Public Types | |
enum | Status { NoError = 0 , AccessError , FormatError } |
The following status values are possible: More... | |
enum | Format { NativeFormat , IniFormat , InvalidFormat = 16 , CustomFormat1 , CustomFormat2 , CustomFormat3 , CustomFormat4 , CustomFormat5 , CustomFormat6 , CustomFormat7 , CustomFormat8 , CustomFormat9 , CustomFormat10 , CustomFormat11 , CustomFormat12 , CustomFormat13 , CustomFormat14 , CustomFormat15 , CustomFormat16 } |
This enum type specifies the storage format used by QSettings. More... | |
enum | Scope { UserScope , SystemScope } |
This enum specifies whether settings are user-specific or shared by all users of the same system. More... | |
typedef QMap< QString, QVariant > | SettingsMap |
Typedef for QMap<QString, QVariant>. | |
typedef bool(* | ReadFunc) (QIODevice &device, SettingsMap &map) |
Typedef for a pointer to a function with the following signature: | |
typedef bool(* | WriteFunc) (QIODevice &device, const SettingsMap &map) |
Typedef for a pointer to a function with the following signature: | |
Public Member Functions | |
QSettings (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. | |
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. | |
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. | |
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. | |
QSettings (QObject *parent=nullptr) | |
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(). | |
QSettings (Scope scope, QObject *parent=nullptr) | |
~QSettings () | |
Destroys the QSettings object. | |
void | clear () |
Removes all entries in the primary location associated to this QSettings object. | |
void | sync () |
Writes any unsaved changes to permanent storage, and reloads any settings that have been changed in the meantime by another application. | |
Status | status () const |
Returns a status code indicating the first error that was met by QSettings, or QSettings::NoError if no error occurred. | |
bool | isAtomicSyncRequired () const |
void | setAtomicSyncRequired (bool enable) |
void | beginGroup (QAnyStringView prefix) |
Appends prefix to the current group. | |
void | endGroup () |
Resets the group to what it was before the corresponding beginGroup() call. | |
QString | group () const |
Returns the current group. | |
int | beginReadArray (QAnyStringView prefix) |
Adds prefix to the current group and starts reading from an array. | |
void | beginWriteArray (QAnyStringView prefix, int size=-1) |
Adds prefix to the current group and starts writing an array of size size. | |
void | endArray () |
Closes the array that was started using beginReadArray() or beginWriteArray(). | |
void | setArrayIndex (int i) |
Sets the current array index to i. | |
QStringList | allKeys () const |
Returns a list of all keys, including subkeys, that can be read using the QSettings object. | |
QStringList | childKeys () const |
Returns a list of all top-level keys that can be read using the QSettings object. | |
QStringList | childGroups () const |
Returns a list of all key top-level groups that contain keys that can be read using the QSettings object. | |
bool | isWritable () const |
Returns true if settings can be written using this QSettings object; returns false otherwise. | |
void | setValue (QAnyStringView key, const QVariant &value) |
Sets the value of setting key to value. | |
QVariant | value (QAnyStringView key, const QVariant &defaultValue) const |
Returns the value for setting key. | |
QVariant | value (QAnyStringView key) const |
void | remove (QAnyStringView key) |
Removes the setting key and any sub-settings of key. | |
bool | contains (QAnyStringView key) const |
Returns true if there exists a setting called key; returns false otherwise. | |
void | setFallbacksEnabled (bool b) |
Sets whether fallbacks are enabled to b. | |
bool | fallbacksEnabled () const |
Returns true if fallbacks are enabled; returns false otherwise. | |
QString | fileName () const |
Returns the path where settings written using this QSettings object are stored. | |
Format | format () const |
Scope | scope () const |
QString | organizationName () const |
QString | applicationName () const |
![]() | |
Q_INVOKABLE | QObject (QObject *parent=nullptr) |
Constructs an object with parent object parent. | |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. | |
virtual bool | event (QEvent *event) |
This virtual function receives events to an object and should return true if the event e was recognized and processed. | |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
Filters events if this object has been installed as an event filter for the watched object. | |
QString | objectName () const |
Q_WEAK_OVERLOAD void | setObjectName (const QString &name) |
Sets the object's name to name. | |
void | setObjectName (QAnyStringView name) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QBindable< QString > | bindableObjectName () |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false . | |
bool | isWindowType () const |
Returns true if the object is a window; otherwise returns false . | |
bool | isQuickItemType () const |
Returns true if the object is a QQuickItem; otherwise returns false . | |
bool | signalsBlocked () const noexcept |
Returns true if signals are blocked; otherwise returns false . | |
bool | blockSignals (bool b) noexcept |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). | |
QThread * | thread () const |
Returns the thread in which the object lives. | |
void | moveToThread (QThread *thread) |
Changes the thread affinity for this object and its children. | |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds. | |
int | startTimer (std::chrono::milliseconds time, Qt::TimerType timerType=Qt::CoarseTimer) |
void | killTimer (int id) |
Kills the timer with timer identifier, id. | |
template<typename T > | |
T | findChild (const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object. | |
template<typename T > | |
QList< T > | findChildren (const QString &aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. | |
template<typename T > | |
QList< T > | findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const QObjectList & | children () const |
Returns a list of child objects. | |
void | setParent (QObject *parent) |
Makes the object a child of parent. | |
void | installEventFilter (QObject *filterObj) |
Installs an event filter filterObj on this object. | |
void | removeEventFilter (QObject *obj) |
Removes an event filter object obj from this object. | |
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 |
Dumps a tree of children to the debug output. | |
void | dumpObjectInfo () const |
Dumps information about signal connections, etc. | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. | |
bool | setProperty (const char *name, QVariant &&value) |
QVariant | property (const char *name) const |
Returns the value of the object's name property. | |
QList< QByteArray > | dynamicPropertyNames () const |
QBindingStorage * | bindingStorage () |
const QBindingStorage * | bindingStorage () const |
QObject * | parent () const |
Returns a pointer to the parent object. | |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false . | |
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 QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
\threadsafe | |
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::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
\threadsafe | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static bool | disconnect (const QMetaObject::Connection &) |
Disconnect a 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 |
\reimp | |
![]() | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr. | |
int | senderSignalIndex () const |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. | |
bool | isSignalConnected (const QMetaMethod &signal) const |
virtual void | timerEvent (QTimerEvent *event) |
This event handler can be reimplemented in a subclass to receive timer events for the object. | |
virtual void | childEvent (QChildEvent *event) |
This event handler can be reimplemented in a subclass to receive child events. | |
virtual void | customEvent (QEvent *event) |
This event handler can be reimplemented in a subclass to receive custom events. | |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
QObject (QObjectPrivate &dd, QObject *parent=nullptr) | |
Additional Inherited Members | |
![]() | |
void | deleteLater () |
\threadsafe | |
![]() | |
void | destroyed (QObject *=nullptr) |
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked. | |
void | objectNameChanged (const QString &objectName, QPrivateSignal) |
This signal is emitted after the object's name has been changed. | |
![]() | |
QScopedPointer< QObjectData > | d_ptr |
![]() | |
QString | objectName |
the name of this object | |
![]() | |
template< class T > T | qobject_cast (const QObject *object) |
Returns the given object cast to type T if the object is of type T (or of a subclass); otherwise returns \nullptr. | |
template< typename T > T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
template< typename T > QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QObjectList | |
\macro Q_CLASSINFO(Name, Value) | |
\inmodule QtCore
The QSettings class provides persistent platform-independent application settings.
\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 26 of file qsettings.h.
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.
Definition at line 172 of file qsettings.h.
Typedef for QMap<QString, QVariant>.
Definition at line 171 of file qsettings.h.
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.
Definition at line 173 of file qsettings.h.
enum QSettings::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
{@}-based syntax to encode the type. For example:To minimize compatibility issues, any @
that doesn't appear at the first position in the value or that isn't followed by a Qt type (Point
, Rect
, Size
, etc.) is treated as a normal character.
{\}) in file paths:QSettings always treats backslash as a special character and provides no API for reading or writing such entries.
%
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.\endlist
Definition at line 48 of file qsettings.h.
enum QSettings::Scope |
This enum specifies whether settings are user-specific or shared by all users of the same system.
\value UserScope Store settings in a location specific to the current user (e.g., in the user's home directory). \value SystemScope Store settings in a global location, so that all users on the same machine access the same set of settings.
Enumerator | |
---|---|
UserScope | |
SystemScope |
Definition at line 85 of file qsettings.h.
enum QSettings::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).
Enumerator | |
---|---|
NoError | |
AccessError | |
FormatError |
Definition at line 39 of file qsettings.h.
|
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).
Definition at line 2489 of file qsettings.cpp.
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}.
Definition at line 2514 of file qsettings.cpp.
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 2538 of file qsettings.cpp.
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.
.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
@
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. \endlistDefinition at line 2574 of file qsettings.cpp.
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.
Definition at line 2614 of file qsettings.cpp.
Constructs a QSettings object in the same way as QSettings(QObject *parent) but with the given scope.
Definition at line 2627 of file qsettings.cpp.
QSettings::~QSettings | ( | ) |
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:
Definition at line 3073 of file qsettings.cpp.
References QSettingsPrivate::AllKeys, and d.
Referenced by QIconTheme::QIconTheme(), and fontKeys().
QString QSettings::applicationName | ( | ) | const |
Returns the application name used for storing the settings.
Definition at line 2805 of file qsettings.cpp.
References d.
void QSettings::beginGroup | ( | QAnyStringView | 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
\endlistCall endGroup() to reset the current group to what it was before the corresponding beginGroup() call. Groups can be nested.
Definition at line 2900 of file qsettings.cpp.
References d.
Referenced by QQmlSettingsPrivate::instance(), QQuickStylePrivate::settings(), and snippet_ctor2().
int QSettings::beginReadArray | ( | QAnyStringView | 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.
Definition at line 2959 of file qsettings.cpp.
References d.
void QSettings::beginWriteArray | ( | QAnyStringView | 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
To read back an array, use beginReadArray().
Definition at line 2998 of file qsettings.cpp.
References d, remove(), and setValue().
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.
Definition at line 3121 of file qsettings.cpp.
References QSettingsPrivate::ChildGroups, and d.
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.
Definition at line 3097 of file qsettings.cpp.
References QSettingsPrivate::ChildKeys, and d.
Referenced by QHstsStore::readPolicies().
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.
Definition at line 2719 of file qsettings.cpp.
References d.
bool QSettings::contains | ( | QAnyStringView | 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.
Definition at line 3239 of file qsettings.cpp.
References d.
Referenced by QQmlPreviewPosition::initLastSavedWindowPosition(), QLocalServerPrivate::listen(), QQmlPreviewPosition::loadWindowPositionSettings(), and QLocalServerPrivate::removeServer().
|
static |
Returns default file format used for storing settings for the QSettings(QObject *) constructor. If no default format is set, QSettings::NativeFormat is used.
Definition at line 3360 of file qsettings.cpp.
References globalDefaultFormat.
void QSettings::endArray | ( | ) |
Closes the array that was started using beginReadArray() or beginWriteArray().
Definition at line 3015 of file qsettings.cpp.
References d, qWarning, and setValue().
void QSettings::endGroup | ( | ) |
Resets the group to what it was before the corresponding beginGroup() call.
Example:
Definition at line 2916 of file qsettings.cpp.
Referenced by snippet_ctor2().
|
overrideprotectedvirtual |
\reimp
Reimplemented from QObject.
Definition at line 3275 of file qsettings.cpp.
References d, QObject::event(), and QEvent::UpdateRequest.
bool QSettings::fallbacksEnabled | ( | ) | const |
Returns true
if fallbacks are enabled; returns false
otherwise.
By default, fallbacks are enabled.
Definition at line 3265 of file qsettings.cpp.
References d.
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.
Definition at line 2753 of file qsettings.cpp.
References d.
Referenced by QQmlSettingsPrivate::init(), QWasmIDBSettingsPrivate_onCheck(), and QWasmIDBSettingsPrivate_onLoad().
QSettings::Format QSettings::format | ( | ) | const |
Returns the format used for storing the settings.
Definition at line 2766 of file qsettings.cpp.
References d.
Referenced by setDefaultFormat(), and QFFmpegImageCapture::setImageSettings().
QString QSettings::group | ( | ) | const |
Returns the current group.
Definition at line 2938 of file qsettings.cpp.
References d.
Referenced by remove().
bool QSettings::isAtomicSyncRequired | ( | ) | const |
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
.
Definition at line 2838 of file qsettings.cpp.
References d.
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.
Definition at line 3139 of file qsettings.cpp.
References d.
Referenced by QHstsStore::isWritable().
QString QSettings::organizationName | ( | ) | const |
Returns the organization name used for storing the settings.
Definition at line 2792 of file qsettings.cpp.
References d.
|
static |
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:
Definition at line 3476 of file qsettings.cpp.
References QList< T >::append(), Qt::CaseSensitive, CustomFormat1, extension(), info, InvalidFormat, Q_ASSERT, settingsGlobalMutex, and QList< T >::size().
Referenced by main().
void QSettings::remove | ( | QAnyStringView | 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.
Definition at line 3201 of file qsettings.cpp.
References d, group(), QString::isEmpty(), and QString::prepend().
Referenced by beginWriteArray(), QLocalServerPrivate::closeServer(), and QLocalServerPrivate::removeServer().
QSettings::Scope QSettings::scope | ( | ) | const |
Returns the scope used for storing the settings.
Definition at line 2779 of file qsettings.cpp.
References d.
Referenced by setPath().
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 3044 of file qsettings.cpp.
References d, i, qMax(), and qWarning.
Referenced by beginWriteArray(), and for().
void QSettings::setAtomicSyncRequired | ( | bool | enable | ) |
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.
Definition at line 2865 of file qsettings.cpp.
References d.
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.
Definition at line 3347 of file qsettings.cpp.
References format(), and globalDefaultFormat.
void QSettings::setFallbacksEnabled | ( | bool | b | ) |
Sets whether fallbacks are enabled to b.
By default, fallbacks are enabled.
Definition at line 3252 of file qsettings.cpp.
References d.
Referenced by QHstsStore::QHstsStore().
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
FOLDERID_RoamingAppData
\row FOLDERID_ProgramData
\row $HOME/
.config \row /etc/xdg
\row $HOME/Settings
\row /etc/xdg
\row $HOME/
.config \row /etc/xdg
\endtableThe 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.
Definition at line 3399 of file qsettings.cpp.
References initDefaultPaths(), QHash< Key, T >::insert(), QHash< Key, T >::isEmpty(), pathHashKey(), scope(), QDir::separator(), and settingsGlobalMutex.
void QSettings::setValue | ( | QAnyStringView | 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:
Definition at line 3164 of file qsettings.cpp.
Referenced by beginWriteArray(), beginWriteArray(), QLocalServerPrivate::closeServer(), endArray(), QLocalServerPrivate::listen(), main(), QQmlLocalStorage::openDatabaseSync(), qmlsqldatabase_changeVersion(), snippet_ctor2(), QQmlSettingsPrivate::store(), QQmlToolingSettings::writeDefaults(), MainWindow::writeSettings(), and QColorDialogStaticData::writeSettings().
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().
Definition at line 2821 of file qsettings.cpp.
References d.
Referenced by QQmlSettingsPrivate::instance(), and QQmlToolingSettings::writeDefaults().
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.
Definition at line 2737 of file qsettings.cpp.
References d.
Referenced by QHstsStore::synchronize(), and QQmlToolingSettings::writeDefaults().
QVariant QSettings::value | ( | QAnyStringView | key | ) | const |
Definition at line 3310 of file qsettings.cpp.
References d.
QVariant QSettings::value | ( | QAnyStringView | 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:
Definition at line 3316 of file qsettings.cpp.
References d.
Referenced by QIconTheme::QIconTheme(), QLocalSocket::connectToServer(), QFileDialogPrivate::createWidgets(), QWindowsDirect2DPaintEnginePrivate::fontFaceFromFontEngine(), fontKeys(), for(), QFileDialogPrivate::init(), QQmlPreviewPosition::initLastSavedWindowPosition(), QQmlSettingsPrivate::load(), QQmlPreviewPosition::loadWindowPositionSettings(), main(), QQmlLocalStorage::openDatabaseSync(), QLibraryInfo::platformPluginArguments(), readInputFile(), MainWindow::readSettings(), QColorDialogStaticData::readSettings(), QQuickStyleSpec::resolve(), resolveSetting(), resolveSetting(), resolveSetting(), snippet_ctor2(), and QWindowsScreen::subpixelAntialiasingTypeHint().