.BI "void \fBbeginGroup\fR ( const QString & group )"
.br
.ti -1c
.BI "void \fBendGroup\fR ()"
.br
.ti -1c
.BI "void \fBresetGroup\fR ()"
.br
.ti -1c
.BI "QString \fBgroup\fR () const"
.br
.in -1c
.SH DESCRIPTION
The QSettings class provides persistent platform-independent application settings.
.PP
On Unix systems, QSettings uses text files to store settings. On Windows systems, QSettings uses the system registry. On Mac OS X, QSettings uses the Carbon preferences API.
.PP
Each setting comprises an identifying key and the data associated with the key. A key is a unicode string which consists of \fItwo\fR or more subkeys. A subkey is a slash, '/', followed by one or more unicode characters (excluding slashes, newlines, carriage returns and equals, '=', signs). The associated data, called the entry or value, may be a boolean, an integer, a double, a string or a list of strings. Entry strings may contain any unicode characters.
.PP
If you want to save and restore the entire desktop's settings, i.e. which applications are running, use QSettings to save the settings for each individual application and QSessionManager to save the desktop's session.
.PP
Example settings:
.PP
.nf
.br
/MyCompany/MyApplication/background color
.br
/MyCompany/MyApplication/foreground color
.br
/MyCompany/MyApplication/geometry/x
.br
/MyCompany/MyApplication/geometry/y
.br
/MyCompany/MyApplication/geometry/width
.br
/MyCompany/MyApplication/geometry/height
.br
/MyCompany/MyApplication/recent files/1
.br
/MyCompany/MyApplication/recent files/2
.br
/MyCompany/MyApplication/recent files/3
.br
.fi
Each line above is a complete key, made up of subkeys.
.PP
A typical usage pattern for reading settings at application startup:
Since settings for Windows are stored in the registry there are some size limitations as follows:
.TP
A subkey may not exceed 255 characters.
.TP
An entry's value may not exceed 16,300 characters.
.TP
All the values of a key (for example, all the 'recent files' subkeys values), may not exceed 65,535 characters.
.PP
These limitations are not enforced on Unix or Mac OS X.
.PP
\fBWarning:\fR Creating multiple, simultaneous instances of QSettings writing to a text file may lead to data loss! This is a known issue which will be fixed in a future release of Qt.
.SH "Notes for Mac OS X Applications"
The location where settings are stored is not formally defined by the CFPreferences API.
.PP
At the time of writing settings are stored (either on a global or user basis, preferring locally) into a plist file in \fC$ROOT/System/Library/Preferences\fR (in XML format). QSettings will create an appropriate plist file (\fCcom.<first group name>.plist\fR) out of the full path to a key.
.PP
For further information on CFPreferences see Apple's Specifications
.SH "Notes for Unix Applications"
There is no universally accepted place for storing application settings under Unix. In the examples the settings file will be searched for in the following directories: <ol type=1>
.TP
\fCSYSCONF\fR - the default value is \fCINSTALL/etc/settings\fR
.TP
\fC/opt/MyCompany/share/etc\fR
.TP
\fC/opt/MyCompany/share/MyApplication/etc\fR
.TP
\fC$HOME/.qt\fR When reading settings the files are searched in the order shown above, with later settings overriding earlier settings. Files for which the user doesn't have read permission are ignored. When saving settings QSettings works in the order shown above, writing to the first settings file for which the user has write permission. (\fCINSTALL\fR is the directory where Qt was installed. This can be modified by using the configure script's -prefix argument )
.PP
If you want to put the settings in a particular place in the filesystem you could do this:
will end up writing the "geometry/width" setting to the file \fC$HOME/.qt/myapplicationrc\fR (assuming that the application is being run by an ordinary user, i.e. not by root).
.PP
For cross-platform applications you should ensure that the Windows size limitations are not exceeded.
.PP
\fBWarning:\fR QSettings doesn't write the settings until it is destroyed so you should construct the QSettings object on the stack.
.PP
See also Input/Output and Networking and Miscellaneous Classes.
.SS "Member Type Documentation"
.SH "QSettings::Format"
.TP
\fCQSettings::Native\fR - Store the settings in a platform dependent location
.TP
\fCQSettings::Ini\fR - Store the settings in a text file
.SH "QSettings::Scope"
.TP
\fCQSettings::Global\fR - Save settings as global as possible
.TP
\fCQSettings::User\fR - Save settings in user space
.SH "QSettings::System"
.TP
\fCQSettings::Mac\fR - Macintosh execution environments
.TP
\fCQSettings::Unix\fR - Mac OS X, Unix, Linux and Unix-like execution environments
.TP
\fCQSettings::Windows\fR - Windows execution environments
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QSettings::QSettings ()"
Creates a settings object.
.PP
Be aware that you must call setPath() or insertSearchPath() before you can use the QSettings object.
.SH "QSettings::QSettings ( Format format )"
Creates a settings object. If \fIformat\fR is 'Ini' the settings will be stored in a text file, using the Unix strategy (see above). If \fIformat\fR is 'Native', the settings will be stored in a platform specific way (ie. the Windows registry).
.PP
Be aware that you must call setPath() or insertSearchPath() before you can use the QSettings object.
.SH "QSettings::~QSettings ()"
Destroys the settings object. All modifications made to the settings will automatically be saved.
.SH "void QSettings::beginGroup ( const QString & group )"
Appends \fIgroup\fR to the current key prefix.
.PP
.nf
.br
QSettings settings;
.br
settings.beginGroup( "/MainWindow" );
.br
// read values
.br
settings.endGroup();
.br
.fi
.SH "void QSettings::endGroup ()"
Undo previous calls to beginGroup(). Note that a single beginGroup("a/b/c") is undone by a single call to endGroup().
In the above example, \fCkeys\fR will contain 'background color' and 'foreground color'. It will not contain 'geometry' because this key contains subkeys not entries.
.PP
To access the geometry values, you could either use subkeyList() to read the keys then read each entry, or simply read each entry directly by specifying its full key, e.g." /MyCompany/MyApplication/geometry/y".
.PP
See also subkeyList().
.SH "QString QSettings::group () const"
Returns the current key prefix, or a null string if there is no key prefix set.
Inserts \fIpath\fR into the settings search path. The semantics of \fIpath\fR depends on the system \fIs\fR. It is usually easier and better to use setPath() instead of this function.
.PP
When \fIs\fR is \fIWindows\fR and the execution environment is \fInot\fR Windows the function does nothing. Similarly when \fIs\fR is \fIUnix\fR and the execution environment is \fInot\fR Unix the function does nothing.
.PP
When \fIs\fR is \fIWindows\fR, and the execution environment is Windows, the search path list will be used as the first subfolder of the "Software" folder in the registry.
.PP
When reading settings the folders are searched forwards from the first folder (listed below) to the last, returning the first settings found, and ignoring any folders for which the user doesn't have read permission. <ol type=1>
settings.writeEntry( "/MyApplication/Tip of the day", TRUE );
.br
.fi
The code above will write the subkey "Tip of the day" into the \fIfirst\fR of the registry folders listed below that is found and for which the user has write permission. <ol type=1>
HKEY_CURRENT_USER/Software/MyApplication If a setting is found in the HKEY_CURRENT_USER space, this setting is overwritten independently of write permissions in the HKEY_LOCAL_MACHINE space.
.PP
When \fIs\fR is \fIUnix\fR, and the execution environment is Unix, the search path list will be used when trying to determine a suitable filename for reading and writing settings files. By default, there are two entries in the search path:
.PP
<ol type=1>
.TP
\fCSYSCONF\fR - where \fCSYSCONF\fR is a directory specified when configuring Qt; by default it is INSTALL/etc/settings.
.TP
\fC$HOME/.qt/\fR - where \fC$HOME\fR is the user's home directory.
.PP
All insertions into the search path will go before $HOME/.qt/. For example:
$HOME/.qt When reading settings the files are searched in the order shown above, with later settings overriding earlier settings. Files for which the user doesn't have read permission are ignored. When saving settings QSettings works in the order shown above, writing to the first settings file for which the user has write permission.
.PP
Note that paths in the file system are not created by this function, so they must already exist to be useful.
.PP
Settings under Unix are stored in files whose names are based on the first subkey of the key (not including the search path). The algorithm for creating names is essentially: lowercase the first subkey, replace spaces with underscores and add 'rc', e.g. \fC/MyCompany/MyApplication/background color\fR will be stored in \fCmyapplicationrc\fR (assuming that \fC/MyCompany\fR is part of the search path).
Reads the entry specified by \fIkey\fR, and returns a bool, or the default value, \fIdef\fR, if the entry couldn't be read. If \fIok\fR is non-null, *ok is set to TRUE if the key was read, FALSE otherwise.
.PP
See also readEntry(), readNumEntry(), readDoubleEntry(), writeEntry(), and removeEntry().
Reads the entry specified by \fIkey\fR, and returns a double, or the default value, \fIdef\fR, if the entry couldn't be read. If \fIok\fR is non-null, *ok is set to TRUE if the key was read, FALSE otherwise.
.PP
See also readEntry(), readNumEntry(), readBoolEntry(), writeEntry(), and removeEntry().
Reads the entry specified by \fIkey\fR, and returns a QString, or the default value, \fIdef\fR, if the entry couldn't be read. If \fIok\fR is non-null, *ok is set to TRUE if the key was read, FALSE otherwise.
.PP
See also readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), writeEntry(), and removeEntry().
Reads the entry specified by \fIkey\fR as a string. If \fIok\fR is not 0, \fI*ok\fR is set to TRUE if the key was read, otherwise \fI*ok\fR is set to FALSE.
.PP
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
.PP
.nf
.br
QStringList list = mySettings.readListEntry( "recentfiles" );
.br
QStringList::Iterator it = list.begin();
.br
while( it != list.end() ) {
.br
myProcessing( *it );
.br
++it;
.br
}
.br
.fi
.PP
See also readEntry(), readDoubleEntry(), readBoolEntry(), writeEntry(), removeEntry(), and QStringList::split().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.PP
Reads the entry specified by \fIkey\fR as a string. The \fIseparator\fR is used to create a QStringList by calling QStringList::split(\fIseparator\fR, entry). If \fIok\fR is not 0: \fI*ok\fR is set to TRUE if the key was read, otherwise \fI*ok\fR is set to FALSE.
.PP
\fBWarning:\fR As the documentation states, QStringList::split() will omit empty strings from the list. Because of this, it is impossible to retrieve identical list data with this function. We recommend using the readListEntry() and writeEntry() overloads that do not take a \fIseparator\fR argument.
.PP
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
.PP
.nf
.br
QStringList list = mySettings.readListEntry( "size", " " );
.br
QStringList::Iterator it = list.begin();
.br
while( it != list.end() ) {
.br
myProcessing( *it );
.br
++it;
.br
}
.br
.fi
.PP
See also readEntry(), readDoubleEntry(), readBoolEntry(), writeEntry(), removeEntry(), and QStringList::split().
.SH "int QSettings::readNumEntry ( const QString & key, int def = 0, bool * ok = 0 ) const"
Reads the entry specified by \fIkey\fR, and returns an integer, or the default value, \fIdef\fR, if the entry couldn't be read. If \fIok\fR is non-null, *ok is set to TRUE if the key was read, FALSE otherwise.
.PP
See also readEntry(), readDoubleEntry(), readBoolEntry(), writeEntry(), and removeEntry().
Returns true if the entry was successfully removed; otherwise returns false. Note that removing the last entry in any given folder, will also remove the folder.
Removes all occurrences of \fIpath\fR (using exact matching) from the settings search path for system \fIs\fR. Note that the default search paths cannot be removed.
Insert platform-dependent paths from platform-independent information.
.PP
The \fIdomain\fR should be an Internet domain name controlled by the producer of the software, eg. Trolltech products use "trolltech.com".
.PP
The \fIproduct\fR should be the official name of the product.
.PP
The \fIscope\fR should be QSettings::User for user-specific settings, or QSettings::Global for system-wide settings (generally these will be read-only to many users).
In the above example, \fCkeys\fR will contain 'geometry' and 'recent files'. It will not contain 'background color' or 'foreground color' because those keys contain entries not subkeys. To get a list of keys that contain entries rather than subkeys use entryList() instead.
.PP
\fBWarning:\fR In the above example, if QSettings is writing to an Ini file, then a call to
.PP
.nf
.br
subkeyList("/MyCompany")
.fi
will return an empty list. This happens because a key like
.PP
.nf
.br
/MyCompany/MyApplication/background color
.fi
is written to the file \fI"mycompanyrc"\fR, under the section \fI[MyApplication]\fR. This call is therefore a request to list the sections in an ini file, which is not supported in this version of QSettings. This is a known issue which will be fixed in Qt-4.
Writes the boolean entry \fIvalue\fR into key \fIkey\fR. The \fIkey\fR is created if it doesn't exist. Any previous value is overwritten by \fIvalue\fR.
.PP
If an error occurs the settings are left unchanged and FALSE is returned; otherwise TRUE is returned.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Writes the double entry \fIvalue\fR into key \fIkey\fR. The \fIkey\fR is created if it doesn't exist. Any previous value is overwritten by \fIvalue\fR.
.PP
If an error occurs the settings are left unchanged and FALSE is returned; otherwise TRUE is returned.
.PP
See also readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), and removeEntry().
.SH "bool QSettings::writeEntry ( const QString & key, int value )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Writes the integer entry \fIvalue\fR into key \fIkey\fR. The \fIkey\fR is created if it doesn't exist. Any previous value is overwritten by \fIvalue\fR.
.PP
If an error occurs the settings are left unchanged and FALSE is returned; otherwise TRUE is returned.
.PP
See also readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), and removeEntry().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Writes the string entry \fIvalue\fR into key \fIkey\fR. The \fIkey\fR is created if it doesn't exist. Any previous value is overwritten by \fIvalue\fR. If \fIvalue\fR is an empty string or a null string the key's value will be an empty string.
.PP
If an error occurs the settings are left unchanged and FALSE is returned; otherwise TRUE is returned.
.PP
See also readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), and removeEntry().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Writes the string list entry \fIvalue\fR into key \fIkey\fR. The \fIkey\fR is created if it doesn't exist. Any previous value is overwritten by \fIvalue\fR.
.PP
If an error occurs the settings are left unchanged and FALSE is returned; otherwise returns TRUE.
.PP
See also readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), and removeEntry().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.PP
Writes the string list entry \fIvalue\fR into key \fIkey\fR. The \fIkey\fR is created if it doesn't exist. Any previous value is overwritten by \fIvalue\fR. The list is stored as a sequence of strings separated by \fIseparator\fR (using QStringList::join()), so none of the strings in the list should contain the separator. If the list is empty or null the key's value will be an empty string.
.PP
\fBWarning:\fR The list should not contain empty or null strings, as readListEntry() will use QStringList::split() to recreate the list. As the documentation states, QStringList::split() will omit empty strings from the list. Because of this, it is impossible to retrieve identical list data that is stored with this function. We recommend using the writeEntry() and readListEntry() overloads that do not take a \fIseparator\fR argument.
.PP
If an error occurs the settings are left unchanged and FALSE is returned; otherwise returns TRUE.
.PP
See also readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), removeEntry(), and QStringList::join().