qt-4.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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=0)
 
 QSettings (Scope scope, const QString &organization, const QString &application=QString(), QObject *parent=0)
 
 QSettings (Format format, Scope scope, const QString &organization, const QString &application=QString(), QObject *parent=0)
 
 QSettings (const QString &fileName, Format format, QObject *parent=0)
 
 QSettings (QObject *parent=0)
 
 ~QSettings ()
 
void clear ()
 
void sync ()
 
Status status () const
 
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=QVariant()) 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
 
void setIniCodec (QTextCodec *codec)
 
void setIniCodec (const char *codecName)
 
QTextCodeciniCodec () const
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=0)
 
virtual ~QObject ()
 
virtual bool eventFilter (QObject *, QEvent *)
 
QString objectName () const
 
void setObjectName (const QString &name)
 
bool isWidgetType () const
 
bool signalsBlocked () const
 
bool blockSignals (bool b)
 
QThreadthread () const
 
void moveToThread (QThread *thread)
 
int startTimer (int interval)
 
void killTimer (int id)
 
template<typename T >
findChild (const QString &aName=QString()) const
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
const QObjectListchildren () const
 
void setParent (QObject *)
 
void installEventFilter (QObject *)
 
void removeEventFilter (QObject *)
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectTree ()
 
void dumpObjectInfo ()
 
bool setProperty (const char *name, const QVariant &value)
 
QVariant property (const char *name) const
 
QList< QByteArraydynamicPropertyNames () const
 
void setUserData (uint id, QObjectUserData *data)
 
QObjectUserDatauserData (uint id) const
 
QObjectparent () const
 
bool inherits (const char *classname) const
 

Static Public Member Functions

static void setDefaultFormat (Format format)
 
static Format defaultFormat ()
 
static void setSystemIniPath (const QString &dir)
 
static void setUserIniPath (const QString &dir)
 
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 bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, 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 uint registerUserData ()
 

Protected Member Functions

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

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Attributes inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

The QSettings class provides persistent platform-independent application settings.

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 XML preferences files on Mac OS X. 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 {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 73 of file qsettings.h.

Member Typedef Documentation

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 191 of file qsettings.h.

Typedef for QMap<QString, QVariant>.

See also
registerFormat()

Definition at line 190 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.

See also
ReadFunc, registerFormat()

Definition at line 192 of file qsettings.h.

Member Enumeration Documentation

This enum type specifies the storage format used by QSettings.

NativeFormat Store the settings using the most appropriate storage format for the platform. On Windows, this means the system registry; on Mac OS X, this means the CFPreferences API; on Unix, this means textual configuration files in INI format. IniFormat Store the settings in INI files. InvalidFormat Special value returned by registerFormat(). CustomFormat1 CustomFormat2 CustomFormat3 CustomFormat4 CustomFormat5 CustomFormat6 CustomFormat7 CustomFormat8 CustomFormat9 CustomFormat10 CustomFormat11 CustomFormat12 CustomFormat13 CustomFormat14 CustomFormat15 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:

If you store types that QVariant can't convert to QString (e.g., QPoint, QRect, and QSize), Qt uses an {

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

Definition at line 92 of file qsettings.h.

) 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 the a key such as "General/someKey", the key will be located in the "%General" section, not in the "General" section.

Following the philosophy that we should be liberal in what we accept and conservative in what we generate, QSettings will accept Latin-1 encoded INI files, but generate pure ASCII files, where non-ASCII values are encoded using standard INI escape sequences. To make the INI files more readable (but potentially less compatible), call setIniCodec().

See also
registerFormat(), setPath()

This enum specifies whether settings are user-specific or shared by all users of the same system.

UserScope Store settings in a location specific to the current user (e.g., in the user's home directory). SystemScope Store settings in a global location, so that all users on the same machine access the same set of settings. User Global

See also
setPath()
Enumerator
UserScope 
SystemScope 

Definition at line 115 of file qsettings.h.

115  {
116  UserScope,
118 #ifdef QT3_SUPPORT
119  ,
120  User = UserScope,
121  Global = SystemScope
122 #endif
123  };

The following status values are possible:

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

See also
status()
Enumerator
NoError 
AccessError 
FormatError 

Definition at line 86 of file qsettings.h.

Constructor & Destructor Documentation

QSettings::QSettings ( const QString organization,
const QString application = QString(),
QObject parent = 0 
)
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 2658 of file qsettings.cpp.

2659  : QObject(*QSettingsPrivate::create(NativeFormat, UserScope, organization, application),
2660  parent)
2661 {
2662 }
static QSettingsPrivate * create(QSettings::Format format, QSettings::Scope scope, const QString &organization, const QString &application)
Definition: qsettings.cpp:366
Q_INVOKABLE QObject(QObject *parent=0)
Definition: qobject.cpp:747
QSettings::QSettings ( Scope  scope,
const QString organization,
const QString application = QString(),
QObject parent = 0 
)

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 {Fallback Mechanism}{locations}.

See also
setDefaultFormat()

Definition at line 2683 of file qsettings.cpp.

2685  : QObject(*QSettingsPrivate::create(NativeFormat, scope, organization, application), parent)
2686 {
2687 }
static QSettingsPrivate * create(QSettings::Format format, QSettings::Scope scope, const QString &organization, const QString &application)
Definition: qsettings.cpp:366
Scope scope() const
Definition: qsettings.cpp:2915
Q_INVOKABLE QObject(QObject *parent=0)
Definition: qobject.cpp:747
QSettings::QSettings ( Format  format,
Scope  scope,
const QString organization,
const QString application = QString(),
QObject parent = 0 
)

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 {Fallback Mechanism}{locations}.

Definition at line 2707 of file qsettings.cpp.

2709  : QObject(*QSettingsPrivate::create(format, scope, organization, application), parent)
2710 {
2711 }
static QSettingsPrivate * create(QSettings::Format format, QSettings::Scope scope, const QString &organization, const QString &application)
Definition: qsettings.cpp:366
Scope scope() const
Definition: qsettings.cpp:2915
Q_INVOKABLE QObject(QObject *parent=0)
Definition: qobject.cpp:747
QSettings::QSettings ( const QString fileName,
Format  format,
QObject parent = 0 
)

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 Mac OS X, 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:

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., ), and might therefore misinterpret it when it occurs in pure INI files.

See also
fileName()

Definition at line 2743 of file qsettings.cpp.

2744  : QObject(*QSettingsPrivate::create(fileName, format), parent)
2745 {
2746 }
static QSettingsPrivate * create(QSettings::Format format, QSettings::Scope scope, const QString &organization, const QString &application)
Definition: qsettings.cpp:366
Q_INVOKABLE QObject(QObject *parent=0)
Definition: qobject.cpp:747
QSettings::QSettings ( QObject parent = 0)
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.

On Mac OS X, if both a name and an Internet domain are specified for the organization, the domain is preferred over the name. On other platforms, the name is preferred over the domain.

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

Definition at line 2782 of file qsettings.cpp.

2783  : QObject(*QSettingsPrivate::create(globalDefaultFormat, UserScope,
2784 #ifdef Q_OS_MAC
2788 #else
2792 #endif
2794  parent)
2795 {
2796 }
static QSettingsPrivate * create(QSettings::Format format, QSettings::Scope scope, const QString &organization, const QString &application)
Definition: qsettings.cpp:366
static QString organizationName()
static QString organizationDomain()
static QString applicationName()
Q_INVOKABLE QObject(QObject *parent=0)
Definition: qobject.cpp:747
QSettings::~QSettings ( )

Destroys the QSettings object.

Any unsaved changes will eventually be written to permanent storage.

See also
sync()

Definition at line 2833 of file qsettings.cpp.

References d.

2834 {
2835  Q_D(QSettings);
2836  if (d->pendingChanges) {
2837  QT_TRY {
2838  d->flush();
2839  } QT_CATCH(...) {
2840  ; // ok. then don't flush but at least don't throw in the destructor
2841  }
2842  }
2843 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73

Member Function Documentation

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 3211 of file qsettings.cpp.

References QSettingsPrivate::AllKeys, and d.

3212 {
3213  Q_D(const QSettings);
3214  return d->children(d->groupPrefix, QSettingsPrivate::AllKeys);
3215 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
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 2941 of file qsettings.cpp.

References d.

2942 {
2943  Q_D(const QSettings);
2944  return d->applicationName;
2945 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
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:

mainwindow/size mainwindow/fullScreen outputpanel/visible

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 3044 of file qsettings.cpp.

References d.

Referenced by QFileDialogPrivate::init(), QLibraryInfo::location(), QMultiInputContext::QMultiInputContext(), QPSPrintEnginePrivate::QPSPrintEnginePrivate(), qt_init(), MetaObjectGenerator::readClassInfo(), QAxBase::setControl(), QGuiPlatformPlugin::systemIconThemeName(), and QFileDialog::~QFileDialog().

3045 {
3046  Q_D(QSettings);
3047  d->beginGroupOrArray(QSettingsGroup(d->normalizedKey(prefix)));
3048 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73

Here is the caller graph for this function:

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 3100 of file qsettings.cpp.

References d, QLatin1String(), QVariant::toInt(), and value().

3101 {
3102  Q_D(QSettings);
3103  d->beginGroupOrArray(QSettingsGroup(d->normalizedKey(prefix), false));
3104  return value(QLatin1String("size")).toInt();
3105 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
QT_BEGIN_NAMESPACE QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int toInt(bool *ok=0) const
Definition: qvariant.cpp:2457
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: qsettings.cpp:3431

Here is the call graph for this function:

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

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

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

Definition at line 3136 of file qsettings.cpp.

References d, QLatin1String(), and setValue().

3137 {
3138  Q_D(QSettings);
3139  d->beginGroupOrArray(QSettingsGroup(d->normalizedKey(prefix), size < 0));
3140 
3141  if (size < 0)
3142  remove(QLatin1String("size"));
3143  else
3144  setValue(QLatin1String("size"), size);
3145 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
void setValue(const QString &key, const QVariant &value)
Definition: qsettings.cpp:3299
QT_BEGIN_NAMESPACE QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString

Here is the call graph for this function:

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 3259 of file qsettings.cpp.

References QSettingsPrivate::ChildGroups, and d.

Referenced by QLibraryInfo::location(), MetaObjectGenerator::readClassInfo(), and QAxBase::setControl().

3260 {
3261  Q_D(const QSettings);
3262  return d->children(d->groupPrefix, QSettingsPrivate::ChildGroups);
3263 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73

Here is the caller graph for this function:

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 3235 of file qsettings.cpp.

References QSettingsPrivate::ChildKeys, and d.

3236 {
3237  Q_D(const QSettings);
3238  return d->children(d->groupPrefix, QSettingsPrivate::ChildKeys);
3239 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
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 2856 of file qsettings.cpp.

References d.

2857 {
2858  Q_D(QSettings);
2859  d->clear();
2860  d->requestUpdate();
2861 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
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 Carbon Preferences API on Mac OS X uses case-sensitive keys. To avoid portability problems, see the {Section and Key Syntax} rules.

See also
value(), setValue()

Definition at line 3365 of file qsettings.cpp.

References d.

Referenced by QLocalServerPrivate::listen(), QLibraryInfo::location(), qt_applyFontDatabaseSettings(), and QLocalServerPrivate::removeServer().

3366 {
3367  Q_D(const QSettings);
3368  QString k = d->actualKey(key);
3369  return d->get(k, 0);
3370 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
The QString class provides a Unicode character string.
Definition: qstring.h:83

Here is the caller graph for this function:

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 3465 of file qsettings.cpp.

3466 {
3467  return globalDefaultFormat;
3468 }
void QSettings::endArray ( )

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

See also
beginReadArray(), beginWriteArray()

Definition at line 3153 of file qsettings.cpp.

References QSettingsGroup::arraySizeGuess(), d, group(), QSettingsGroup::isArray(), QSettingsGroup::name(), QLatin1String(), qWarning(), setValue(), QString::size(), and QSettingsGroup::toString().

3154 {
3155  Q_D(QSettings);
3156  if (d->groupStack.isEmpty()) {
3157  qWarning("QSettings::endArray: No matching beginArray()");
3158  return;
3159  }
3160 
3161  QSettingsGroup group = d->groupStack.top();
3162  int len = group.toString().size();
3163  d->groupStack.pop();
3164  if (len > 0)
3165  d->groupPrefix.truncate(d->groupPrefix.size() - (len + 1));
3166 
3167  if (group.arraySizeGuess() != -1)
3168  setValue(group.name() + QLatin1String("/size"), group.arraySizeGuess());
3169 
3170  if (!group.isArray())
3171  qWarning("QSettings::endArray: Expected endGroup() instead");
3172 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
void setValue(const QString &key, const QVariant &value)
Definition: qsettings.cpp:3299
QString group() const
Definition: qsettings.cpp:3082
QString name() const
Definition: qsettings_p.h:127
Q_CORE_EXPORT_INLINE QDebug qWarning()
Definition: qdebug.h:289
QT_BEGIN_NAMESPACE QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int arraySizeGuess() const
Definition: qsettings_p.h:130
int size() const
Definition: qstring.h:102
QString toString() const
Definition: qsettings_p.h:139
bool isArray() const
Definition: qsettings_p.h:129

Here is the call graph for this function:

void QSettings::endGroup ( )

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

Example:

See also
beginGroup(), group()

Definition at line 3060 of file qsettings.cpp.

References d, group(), QSettingsGroup::isArray(), qWarning(), QString::size(), and QSettingsGroup::toString().

Referenced by QLibraryInfo::location(), qt_init(), MetaObjectGenerator::readClassInfo(), and QAxBase::setControl().

3061 {
3062  Q_D(QSettings);
3063  if (d->groupStack.isEmpty()) {
3064  qWarning("QSettings::endGroup: No matching beginGroup()");
3065  return;
3066  }
3067 
3068  QSettingsGroup group = d->groupStack.pop();
3069  int len = group.toString().size();
3070  if (len > 0)
3071  d->groupPrefix.truncate(d->groupPrefix.size() - (len + 1));
3072 
3073  if (group.isArray())
3074  qWarning("QSettings::endGroup: Expected endArray() instead");
3075 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
QString group() const
Definition: qsettings.cpp:3082
Q_CORE_EXPORT_INLINE QDebug qWarning()
Definition: qdebug.h:289
int size() const
Definition: qstring.h:102
QString toString() const
Definition: qsettings_p.h:139
bool isArray() const
Definition: qsettings_p.h:129

Here is the call graph for this function:

Here is the caller graph for this function:

bool QSettings::event ( QEvent event)
protectedvirtual

Reimplemented from QObject.

Definition at line 3402 of file qsettings.cpp.

References d, QObject::event(), QEvent::type(), and QEvent::UpdateRequest.

3403 {
3404  Q_D(QSettings);
3405  if (event->type() == QEvent::UpdateRequest) {
3406  d->update();
3407  return true;
3408  }
3409  return QObject::event(event);
3410 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
virtual bool event(QEvent *)
Definition: qobject.cpp:1180
Type type() const
Definition: qcoreevent.h:303

Here is the call graph for this function:

bool QSettings::fallbacksEnabled ( ) const

Returns true if fallbacks are enabled; returns false otherwise.

By default, fallbacks are enabled.

See also
setFallbacksEnabled()

Definition at line 3392 of file qsettings.cpp.

References d.

3393 {
3394  Q_D(const QSettings);
3395  return d->fallbacks;
3396 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
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 2889 of file qsettings.cpp.

References d.

2890 {
2891  Q_D(const QSettings);
2892  return d->fileName();
2893 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
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 2902 of file qsettings.cpp.

References d.

Referenced by setDefaultFormat().

2903 {
2904  Q_D(const QSettings);
2905  return d->format;
2906 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73

Here is the caller graph for this function:

QString QSettings::group ( ) const

Returns the current group.

See also
beginGroup(), endGroup()

Definition at line 3082 of file qsettings.cpp.

References d.

Referenced by endArray(), endGroup(), and remove().

3083 {
3084  Q_D(const QSettings);
3085  return d->groupPrefix.left(d->groupPrefix.size() - 1);
3086 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73

Here is the caller graph for this function:

QTextCodec * QSettings::iniCodec ( ) const
Since
4.5

Returns the codec that is used for accessing INI files. By default, no codec is used, so a null pointer is returned.

Definition at line 2994 of file qsettings.cpp.

References d.

2995 {
2996  Q_D(const QSettings);
2997  return d->iniCodec;
2998 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
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 3277 of file qsettings.cpp.

References d.

Referenced by UpdateRegistry().

3278 {
3279  Q_D(const QSettings);
3280  return d->isWritable();
3281 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73

Here is the caller graph for this function:

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 2928 of file qsettings.cpp.

References d.

2929 {
2930  Q_D(const QSettings);
2931  return d->organizationName;
2932 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
QSettings::Format QSettings::registerFormat ( const QString extension,
ReadFunc  readFunc,
WriteFunc  writeFunc,
Qt::CaseSensitivity  caseSensitivity = Qt::CaseSensitive 
)
static
Since
4.1

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 3617 of file qsettings.cpp.

References QVector< T >::append(), Qt::CaseSensitive, QConfFileCustomFormat::caseSensitivity, CustomFormat1, QConfFileCustomFormat::extension, index, InvalidFormat, QConfFileCustomFormat::readFunc, QVector< T >::size(), and QConfFileCustomFormat::writeFunc.

3620 {
3621 #ifdef QT_QSETTINGS_ALWAYS_CASE_SENSITIVE_AND_FORGET_ORIGINAL_KEY_ORDER
3622  Q_ASSERT(caseSensitivity == Qt::CaseSensitive);
3623 #endif
3624 
3625  QMutexLocker locker(globalMutex());
3626  CustomFormatVector *customFormatVector = customFormatVectorFunc();
3627  int index = customFormatVector->size();
3628  if (index == 16) // the QSettings::Format enum has room for 16 custom formats
3629  return QSettings::InvalidFormat;
3630 
3631  QConfFileCustomFormat info;
3632  info.extension = QLatin1Char('.');
3633  info.extension += extension;
3634  info.readFunc = readFunc;
3635  info.writeFunc = writeFunc;
3636  info.caseSensitivity = caseSensitivity;
3637  customFormatVector->append(info);
3638 
3639  return QSettings::Format((int)QSettings::CustomFormat1 + index);
3640 }
Qt::CaseSensitivity caseSensitivity
Definition: qsettings.cpp:113
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QSettings::WriteFunc writeFunc
Definition: qsettings.cpp:112
QSettings::ReadFunc readFunc
Definition: qsettings.cpp:111
void append(const T &t)
Definition: qvector.h:573
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
quint16 index
int size() const
Definition: qvector.h:137
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

Here is the call graph for this function:

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 Carbon Preferences API on Mac OS X uses case-sensitive keys. To avoid portability problems, see the {Section and Key Syntax} rules.

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

Definition at line 3330 of file qsettings.cpp.

References d, group(), QString::isEmpty(), and QString::prepend().

Referenced by QLocalServerPrivate::closeServer(), QLocalServerPrivate::removeServer(), and UpdateRegistry().

3331 {
3332  Q_D(QSettings);
3333  /*
3334  We cannot use actualKey(), because remove() supports empty
3335  keys. The code is also tricky because of slash handling.
3336  */
3337  QString theKey = d->normalizedKey(key);
3338  if (theKey.isEmpty())
3339  theKey = group();
3340  else
3341  theKey.prepend(d->groupPrefix);
3342 
3343  if (theKey.isEmpty()) {
3344  d->clear();
3345  } else {
3346  d->remove(theKey);
3347  }
3348  d->requestUpdate();
3349 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
QString & prepend(QChar c)
Definition: qstring.h:261
QString group() const
Definition: qsettings.cpp:3082
bool isEmpty() const
Definition: qstring.h:704
The QString class provides a Unicode character string.
Definition: qstring.h:83

Here is the call graph for this function:

Here is the caller graph for this function:

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

Returns the scope used for storing the settings.

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

Definition at line 2915 of file qsettings.cpp.

References d.

2916 {
2917  Q_D(const QSettings);
2918  return d->scope;
2919 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
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 3182 of file qsettings.cpp.

References d, qWarning(), QSettingsGroup::setArrayIndex(), QString::size(), and QSettingsGroup::toString().

3183 {
3184  Q_D(QSettings);
3185  if (d->groupStack.isEmpty() || !d->groupStack.top().isArray()) {
3186  qWarning("QSettings::setArrayIndex: Missing beginArray()");
3187  return;
3188  }
3189 
3190  QSettingsGroup &top = d->groupStack.top();
3191  int len = top.toString().size();
3192  top.setArrayIndex(qMax(i, 0));
3193  d->groupPrefix.replace(d->groupPrefix.size() - len - 1, len, top.toString());
3194 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
Q_CORE_EXPORT_INLINE QDebug qWarning()
Definition: qdebug.h:289
int size() const
Definition: qstring.h:102
QString toString() const
Definition: qsettings_p.h:139
void setArrayIndex(int i)
Definition: qsettings_p.h:131

Here is the call graph for this function:

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 3452 of file qsettings.cpp.

References format().

3453 {
3454  globalDefaultFormat = format;
3455 }
Format format() const
Definition: qsettings.cpp:2902

Here is the call graph for this function:

void QSettings::setFallbacksEnabled ( bool  b)

Sets whether fallbacks are enabled to b.

By default, fallbacks are enabled.

See also
fallbacksEnabled()

Definition at line 3379 of file qsettings.cpp.

References b, and d.

3380 {
3381  Q_D(QSettings);
3382  d->fallbacks = !!b;
3383 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
unsigned long(*) DUMMYARG SSL_CTX in b)
void QSettings::setIniCodec ( QTextCodec codec)
Since
4.5

Sets the codec for accessing INI files (including .conf files on Unix) to codec. The codec is used for decoding any data that is read from the INI file, and for encoding any data that is written to the file. By default, no codec is used, and non-ASCII characters are encoded using standard INI escape sequences.

Warning
The codec must be set immediately after creating the QSettings object, before accessing any data.
See also
iniCodec()

Definition at line 2963 of file qsettings.cpp.

References d.

2964 {
2965  Q_D(QSettings);
2966  d->iniCodec = codec;
2967 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
void QSettings::setIniCodec ( const char *  codecName)
Since
4.5 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Sets the codec for accessing INI files (including .conf files on Unix) to the QTextCodec for the encoding specified by codecName. Common values for codecName include "ISO 8859-1", "UTF-8", and "UTF-16". If the encoding isn't recognized, nothing happens.

See also
QTextCodec::codecForName()

Definition at line 2980 of file qsettings.cpp.

References QTextCodec::codecForName(), and d.

2981 {
2982  Q_D(QSettings);
2983  if (QTextCodec *codec = QTextCodec::codecForName(codecName))
2984  d->iniCodec = codec;
2985 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
The QTextCodec class provides conversions between text encodings. Qt uses Unicode to store...
Definition: qtextcodec.h:62
static QTextCodec * codecForName(const QByteArray &name)

Here is the call graph for this function:

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:

Platform Format Scope Path {1,2} Windows {1,2} IniFormat UserScope APPDATA% SystemScope COMMON_APPDATA% {1,2} Unix {1,2} NativeFormat, IniFormat UserScope $HOME/.config SystemScope /etc/xdg {1,2} Qt for Embedded Linux {1,2} NativeFormat, IniFormat UserScope $HOME/Settings SystemScope /etc/xdg {1,2} Mac OS X {1,2} IniFormat UserScope $HOME/.config SystemScope /etc/xdg {1,2} Symbian {1,2} NativeFormat, IniFormat UserScope c:/data/.config SystemScope <drive>/private/<uid>

The default UserScope paths on Unix and Mac OS X ($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 and Mac OS X (/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 and Mac OS X has no effect.

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

Definition at line 3540 of file qsettings.cpp.

References QHash< Key, T >::insert(), QHash< Key, T >::isEmpty(), and QDir::separator().

Referenced by setSystemIniPath(), and setUserIniPath().

3541 {
3542  QMutexLocker locker(globalMutex());
3543  PathHash *pathHash = pathHashFunc();
3544  if (pathHash->isEmpty())
3545  initDefaultPaths(&locker);
3546  pathHash->insert(pathHashKey(format, scope), path + QDir::separator());
3547 }
static QChar separator()
Definition: qdir.cpp:1780
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
bool isEmpty() const
Definition: qhash.h:297
Scope scope() const
Definition: qsettings.cpp:2915
iterator insert(const Key &key, const T &value)
Definition: qhash.h:753

Here is the call graph for this function:

Here is the caller graph for this function:

void QSettings::setSystemIniPath ( const QString dir)
static

Use setPath() instead.

setSystemIniPath(path); setPath(QSettings::NativeFormat, QSettings::SystemScope, path); setPath(QSettings::IniFormat, QSettings::SystemScope, path);

Definition at line 3482 of file qsettings.cpp.

References IniFormat, setPath(), and SystemScope.

3483 {
3484  setPath(IniFormat, SystemScope, dir);
3485 #if !defined(Q_OS_WIN) && !defined(Q_OS_MAC)
3487 #endif
3488 }
static void setPath(Format format, Scope scope, const QString &path)
Definition: qsettings.cpp:3540

Here is the call graph for this function:

void QSettings::setUserIniPath ( const QString dir)
static

Use setPath() instead.

Definition at line 3496 of file qsettings.cpp.

References IniFormat, setPath(), and UserScope.

3497 {
3498  setPath(IniFormat, UserScope, dir);
3499 #if !defined(Q_OS_WIN) && !defined(Q_OS_MAC)
3501 #endif
3502 }
static void setPath(Format format, Scope scope, const QString &path)
Definition: qsettings.cpp:3540

Here is the call graph for this function:

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 Carbon Preferences API on Mac OS X uses case-sensitive keys. To avoid portability problems, see the {Section and Key Syntax} rules.

Example:

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

Definition at line 3299 of file qsettings.cpp.

References d.

Referenced by beginWriteArray(), QLocalServerPrivate::closeServer(), endArray(), QLibraryPrivate::isPlugin(), QLocalServerPrivate::listen(), QFactoryLoader::updateDir(), UpdateRegistry(), QColorDialog::~QColorDialog(), QFileDialog::~QFileDialog(), and QScriptEngineDebuggerPrivate::~QScriptEngineDebuggerPrivate().

3300 {
3301  Q_D(QSettings);
3302  QString k = d->actualKey(key);
3303  d->set(k, value);
3304  d->requestUpdate();
3305 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
The QString class provides a Unicode character string.
Definition: qstring.h:83

Here is the caller graph for this function:

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 3012 of file qsettings.cpp.

References d.

Referenced by UpdateRegistry().

3013 {
3014  Q_D(const QSettings);
3015  return d->status;
3016 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73

Here is the caller graph for this 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.

See also
status()

Definition at line 2874 of file qsettings.cpp.

References d.

2875 {
2876  Q_D(QSettings);
2877  d->sync();
2878 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
QVariant QSettings::value ( const QString key,
const QVariant defaultValue = QVariant() 
) 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 Carbon Preferences API on Mac OS X uses case-sensitive keys. To avoid portability problems, see the {Section and Key Syntax} rules.

Example:

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

Definition at line 3431 of file qsettings.cpp.

References d.

Referenced by beginReadArray(), QLocalSocket::connectToServer(), QColorDialogPrivate::init(), QFileDialogPrivate::init(), QLibraryPrivate::isPlugin(), QLibraryInfo::location(), QMultiInputContext::QMultiInputContext(), QPSPrintEnginePrivate::QPSPrintEnginePrivate(), qt_applyFontDatabaseSettings(), qt_init(), qt_mac_update_os_settings(), MetaObjectGenerator::readClassInfo(), MetaObjectGenerator::readEventInfo(), MetaObjectGenerator::readInterfaceInfo(), QAxBase::setControl(), QScriptEngineDebugger::standardWindow(), QGuiPlatformPlugin::systemIconThemeName(), and QFactoryLoader::updateDir().

3432 {
3433  Q_D(const QSettings);
3434  QVariant result = defaultValue;
3435  QString k = d->actualKey(key);
3436  d->get(k, &result);
3437  return result;
3438 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QString class provides a Unicode character string.
Definition: qstring.h:83

Here is the caller graph for this function:


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