~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to doc/html/qsettings.html

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="iso-8859-1"?>
 
2
<!DOCTYPE html
 
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
 
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
5
<!-- /tmp/qt-4.0.0-espenr-1119621036935/qt-x11-opensource-desktop-4.0.0/src/corelib/io/qsettings.cpp -->
 
6
<head>
 
7
    <title>Qt 4.0: QSettings Class Reference</title>
 
8
    <style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
 
9
a:link { color: #004faf; text-decoration: none }
 
10
a:visited { color: #672967; text-decoration: none }
 
11
td.postheader { font-family: sans-serif }
 
12
tr.address { font-family: sans-serif }
 
13
body { background: #ffffff; color: black; }</style>
 
14
</head>
 
15
<body>
 
16
<table border="0" cellpadding="0" cellspacing="0" width="100%">
 
17
<tr>
 
18
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
 
19
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="annotated.html"><font color="#004faf">Annotated</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
 
20
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><h1 align="center">QSettings Class Reference</h1>
 
21
<p>The QSettings class provides persistent platform-independent application settings. <a href="#details">More...</a></p>
 
22
<pre>#include &lt;QSettings&gt;</pre><p>Part of the <a href="qtcore.html">QtCore</a> module.</p>
 
23
<p>Inherits <a href="qobject.html">QObject</a>.</p>
 
24
<p><b>Note:</b> All the functions in this class are <a href="threads.html#reentrant">reentrant</a>.</p>
 
25
<ul>
 
26
<li><a href="qsettings-members.html">List of all members, including inherited members</a></li>
 
27
<li><a href="qsettings-qt3.html">Qt 3 support members</a></li>
 
28
</ul>
 
29
<a name="public-types"></a>
 
30
<h3>Public Types</h3>
 
31
<ul>
 
32
<li><div class="fn"/>enum <b><a href="qsettings.html#Format-enum">Format</a></b> { NativeFormat, IniFormat }</li>
 
33
<li><div class="fn"/>enum <b><a href="qsettings.html#Scope-enum">Scope</a></b> { UserScope, SystemScope }</li>
 
34
<li><div class="fn"/>enum <b><a href="qsettings.html#Status-enum">Status</a></b> { NoError, AccessError, FormatError }</li>
 
35
</ul>
 
36
<a name="public-functions"></a>
 
37
<h3>Public Functions</h3>
 
38
<ul>
 
39
<li><div class="fn"/><b><a href="qsettings.html#QSettings">QSettings</a></b> ( const QString &amp; <i>organization</i>, const QString &amp; <i>application</i> = QString(), QObject * <i>parent</i> = 0 )</li>
 
40
<li><div class="fn"/><b><a href="qsettings.html#QSettings-2">QSettings</a></b> ( Scope <i>scope</i>, const QString &amp; <i>organization</i>, const QString &amp; <i>application</i> = QString(), QObject * <i>parent</i> = 0 )</li>
 
41
<li><div class="fn"/><b><a href="qsettings.html#QSettings-3">QSettings</a></b> ( Format <i>format</i>, Scope <i>scope</i>, const QString &amp; <i>organization</i>, const QString &amp; <i>application</i> = QString(), QObject * <i>parent</i> = 0 )</li>
 
42
<li><div class="fn"/><b><a href="qsettings.html#QSettings-4">QSettings</a></b> ( const QString &amp; <i>fileName</i>, Format <i>format</i>, QObject * <i>parent</i> = 0 )</li>
 
43
<li><div class="fn"/><b><a href="qsettings.html#QSettings-5">QSettings</a></b> ( QObject * <i>parent</i> = 0 )</li>
 
44
<li><div class="fn"/><b><a href="qsettings.html#dtor.QSettings">~QSettings</a></b> ()</li>
 
45
<li><div class="fn"/>QStringList <b><a href="qsettings.html#allKeys">allKeys</a></b> () const</li>
 
46
<li><div class="fn"/>void <b><a href="qsettings.html#beginGroup">beginGroup</a></b> ( const QString &amp; <i>prefix</i> )</li>
 
47
<li><div class="fn"/>int <b><a href="qsettings.html#beginReadArray">beginReadArray</a></b> ( const QString &amp; <i>prefix</i> )</li>
 
48
<li><div class="fn"/>void <b><a href="qsettings.html#beginWriteArray">beginWriteArray</a></b> ( const QString &amp; <i>prefix</i>, int <i>size</i> = -1 )</li>
 
49
<li><div class="fn"/>QStringList <b><a href="qsettings.html#childGroups">childGroups</a></b> () const</li>
 
50
<li><div class="fn"/>QStringList <b><a href="qsettings.html#childKeys">childKeys</a></b> () const</li>
 
51
<li><div class="fn"/>void <b><a href="qsettings.html#clear">clear</a></b> ()</li>
 
52
<li><div class="fn"/>bool <b><a href="qsettings.html#contains">contains</a></b> ( const QString &amp; <i>key</i> ) const</li>
 
53
<li><div class="fn"/>void <b><a href="qsettings.html#endArray">endArray</a></b> ()</li>
 
54
<li><div class="fn"/>void <b><a href="qsettings.html#endGroup">endGroup</a></b> ()</li>
 
55
<li><div class="fn"/>bool <b><a href="qsettings.html#fallbacksEnabled">fallbacksEnabled</a></b> () const</li>
 
56
<li><div class="fn"/>QString <b><a href="qsettings.html#fileName">fileName</a></b> () const</li>
 
57
<li><div class="fn"/>QString <b><a href="qsettings.html#group">group</a></b> () const</li>
 
58
<li><div class="fn"/>bool <b><a href="qsettings.html#isWritable">isWritable</a></b> () const</li>
 
59
<li><div class="fn"/>void <b><a href="qsettings.html#remove">remove</a></b> ( const QString &amp; <i>key</i> )</li>
 
60
<li><div class="fn"/>void <b><a href="qsettings.html#setArrayIndex">setArrayIndex</a></b> ( int <i>i</i> )</li>
 
61
<li><div class="fn"/>void <b><a href="qsettings.html#setFallbacksEnabled">setFallbacksEnabled</a></b> ( bool <i>b</i> )</li>
 
62
<li><div class="fn"/>void <b><a href="qsettings.html#setValue">setValue</a></b> ( const QString &amp; <i>key</i>, const QVariant &amp; <i>value</i> )</li>
 
63
<li><div class="fn"/>Status <b><a href="qsettings.html#status">status</a></b> () const</li>
 
64
<li><div class="fn"/>void <b><a href="qsettings.html#sync">sync</a></b> ()</li>
 
65
<li><div class="fn"/>QVariant <b><a href="qsettings.html#value">value</a></b> ( const QString &amp; <i>key</i>, const QVariant &amp; <i>defaultValue</i> = QVariant() ) const</li>
 
66
</ul>
 
67
<ul>
 
68
<li><div class="fn"/>28 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
 
69
</ul>
 
70
<a name="static-public-members"></a>
 
71
<h3>Static Public Members</h3>
 
72
<ul>
 
73
<li><div class="fn"/>void <b><a href="qsettings.html#setSystemIniPath">setSystemIniPath</a></b> ( const QString &amp; <i>dir</i> )</li>
 
74
<li><div class="fn"/>void <b><a href="qsettings.html#setUserIniPath">setUserIniPath</a></b> ( const QString &amp; <i>dir</i> )</li>
 
75
</ul>
 
76
<ul>
 
77
<li><div class="fn"/>4 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
 
78
</ul>
 
79
<h3>Additional Inherited Members</h3>
 
80
<ul>
 
81
<li><div class="fn"/>1 property inherited from <a href="qobject.html#properties">QObject</a></li>
 
82
<li><div class="fn"/>1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
 
83
<li><div class="fn"/>1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
 
84
<li><div class="fn"/>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
 
85
</ul>
 
86
<a name="details"></a>
 
87
<hr />
 
88
<h2>Detailed Description</h2>
 
89
<p>The QSettings class provides persistent platform-independent application settings.</p>
 
90
<p>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 <a href="winsystem.html#x11">X11</a> and embedded Linux, in the absense of a standard, many applications (including the KDE applications) use INI text files.</p>
 
91
<p>QSettings is an abstraction around these technologies, enabling you to save and restore application settings in a portable manner.</p>
 
92
<p>QSettings's API is based on <a href="qvariant.html">QVariant</a>, allowing you to save most value-based types, such as <a href="qstring.html">QString</a>, <a href="qrect.html">QRect</a>, and <a href="qimage.html">QImage</a>, with the minimum of effort.</p>
 
93
<ul><li><a href="#basic-usage">Basic Usage</a></li>
 
94
<li><a href="#qvariant-and-gui-types">QVariant and GUI Types</a></li>
 
95
<li><a href="#key-syntax">Key Syntax</a></li>
 
96
<li><a href="#fallback-mechanism">Fallback Mechanism</a></li>
 
97
<li><a href="#restoring-the-state-of-a-gui-application">Restoring the State of a GUI Application</a></li>
 
98
<li><a href="#accessing-settings-from-multiple-threads-or-processes-simultaneously">Accessing Settings from Multiple Threads or Processes Simultaneously</a></li>
 
99
<li><a href="#platform-specific-notes">Platform-Specific Notes</a></li>
 
100
</ul>
 
101
<a name="basic-usage"></a>
 
102
<h3>Basic Usage</h3>
 
103
<p>When creating a QSettings object, you must pass the name of your company or organization as well as the name of your application. For example, if your product is called Star Runner and your company is called MySoft, you would construct the QSettings object as follows:</p>
 
104
<pre>&nbsp;       QSettings settings(&quot;mysoft.org&quot;, &quot;StarRunner&quot;);</pre>
 
105
<p>QSettings objects can be created either on the stack or on the heap (i.e. using <tt>new</tt>). Constructing and destroying a QSettings object is very fast.</p>
 
106
<p>If you use QSettings from many places in your application, you might want to specify the organization name and the application name using <a href="qcoreapplication.html#organizationName-prop">QCoreApplication::setOrganizationName</a>() and <a href="qcoreapplication.html#applicationName-prop">QCoreApplication::setApplicationName</a>(), and then use the default QSettings constructor:</p>
 
107
<pre>&nbsp;       QCoreApplication::setOrganizationName(&quot;MySoft&quot;);
 
108
        QCoreApplication::setOrganizationDomain(&quot;mysoft.com&quot;);
 
109
        QCoreApplication::setApplicationName(&quot;Star Runner&quot;);
 
110
        ...
 
111
        QSettings settings;</pre>
 
112
<p>(Here, we also specify the organization's Internet domain. When the Internet domain is set, it is used on Mac OS X instead of the organization name, since Mac OS X applications conventionally use Internet domains to identify themselves. If no domain is set, a fake domain is derived from the organization name. See the <a href="#platform-specific-notes">Platform-Specific Notes</a> below for details.)</p>
 
113
<p>QSettings stores settings. Each setting consists of a <a href="qstring.html">QString</a> that specifies the setting's name (the <i>key</i>) and a <a href="qvariant.html">QVariant</a> that stores the data associated with the key. To write a setting, use <a href="qsettings.html#setValue">setValue</a>(). For example:</p>
 
114
<pre>&nbsp;       settings.setValue(&quot;editor/wrapMargin&quot;, 68);</pre>
 
115
<p>If there already exists a setting with the same key, the existing value is overwritten by the new value. For efficiency, the changes may not be saved to permanent storage immediately. (You can always call <a href="qsettings.html#sync">sync</a>() to commit your changes.)</p>
 
116
<p>You can get a setting's value back using <a href="qsettings.html#value">value</a>():</p>
 
117
<pre>&nbsp;       int margin = settings.value(&quot;editor/wrapMargin&quot;).toInt();</pre>
 
118
<p>If there is no setting with the specified name, QSettings returns a null <a href="qvariant.html">QVariant</a> (which can be converted to the integer 0). You can specify another default value by passing a second argument to <a href="qsettings.html#value">value</a>():</p>
 
119
<pre>&nbsp;       int margin = settings.value(&quot;editor/wrapMargin&quot;, 80).toInt();</pre>
 
120
<p>To test whether a given key exists, call <a href="qsettings.html#contains">contains</a>(). To remove the setting associated with a key, call <a href="qsettings.html#remove">remove</a>(). To obtain the list of all keys, call <a href="qsettings.html#allKeys">allKeys</a>(). To remove all keys, call <a href="qsettings.html#clear">clear</a>().</p>
 
121
<a name="qvariant-and-gui-types"></a>
 
122
<h3>QVariant and GUI Types</h3>
 
123
<p>Because <a href="qvariant.html">QVariant</a> is part of the <a href="qtcore.html#qtcore">QtCore</a> library, it cannot provide conversion functions to data types such as <a href="qcolor.html">QColor</a>, <a href="qimage.html">QImage</a>, and <a href="qpixmap.html">QPixmap</a>, which are part of <a href="qtgui.html#qtgui">QtGui</a>. In other words, there is no <tt>QVariant::toColor()</tt> function.</p>
 
124
<p>Instead, you can use the <a href="qvariant.html#value">QVariant::value</a>() or the <a href="qvariant.html#qVariantValue">qVariantValue</a>() template function. For example:</p>
 
125
<pre>&nbsp;   QSettings settings(&quot;MySoft&quot;, &quot;Star Runner&quot;);
 
126
    QColor color = settings.value(&quot;DataPump/bgcolor&quot;).value&lt;QColor&gt;();</pre>
 
127
<p>The inverse conversion (e.g., from <a href="qcolor.html">QColor</a> to <a href="qvariant.html">QVariant</a>) is automatic for all data types supported by <a href="qvariant.html">QVariant</a>, including GUI-related types:</p>
 
128
<pre>&nbsp;   QSettings settings(&quot;MySoft&quot;, &quot;Star Runner&quot;);
 
129
    QColor color = palette().background().color();
 
130
    settings.setValue(&quot;DataPump/bgcolor&quot;, color);</pre>
 
131
<a name="key-syntax"></a>
 
132
<h3>Key Syntax</h3>
 
133
<p>Setting keys can contain any Unicode characters. 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, follow these two simple rules:</p>
 
134
<ol type="1">
 
135
<li>Always refer to the same key using the same case. For example, if you refer to a key as &quot;text fonts&quot; in one place in your code, don't refer to it as &quot;Text Fonts&quot; somewhere else.</li>
 
136
<li>Avoid key names that are identical except for the case. For example, if you have a key called &quot;<a href="mainwindow.html">MainWindow</a>&quot;, don't try to save another key as &quot;mainwindow&quot;.</li>
 
137
</ol>
 
138
<p>You can form hierarchical keys using the '/' character as a separator, similar to Unix file paths. For example:</p>
 
139
<pre>&nbsp;       settings.setValue(&quot;mainwindow/size&quot;, win-&gt;size());
 
140
        settings.setValue(&quot;mainwindow/fullScreen&quot;, win-&gt;isFullScreen());
 
141
        settings.setValue(&quot;outputpanel/visible&quot;, panel-&gt;isVisible());</pre>
 
142
<p>If you want to save or restore many settings with the same prefix, you can specify the prefix using <a href="qsettings.html#beginGroup">beginGroup</a>() and call <a href="qsettings.html#endGroup">endGroup</a>() at the end. Here's the same example again, but this time using the group mechanism:</p>
 
143
<pre>&nbsp;       settings.beginGroup(&quot;mainwindow&quot;);
 
144
        settings.setValue(&quot;size&quot;, win-&gt;size());
 
145
        settings.setValue(&quot;fullScreen&quot;, win-&gt;isFullScreen());
 
146
        settings.endGroup();
 
147
 
 
148
        settings.beginGroup(&quot;outputpanel&quot;);
 
149
        settings.setValue(&quot;visible&quot;, panel-&gt;isVisible());
 
150
        settings.endGroup();</pre>
 
151
<p>If a group is set using <a href="qsettings.html#beginGroup">beginGroup</a>(), the behavior of most functions changes consequently. Groups can be set recursively.</p>
 
152
<p>In addition to groups, QSettings also supports an &quot;array&quot; concept. See <a href="qsettings.html#beginReadArray">beginReadArray</a>() and <a href="qsettings.html#beginWriteArray">beginWriteArray</a>() for details.</p>
 
153
<a name="fallback-mechanism"></a>
 
154
<h3>Fallback Mechanism</h3>
 
155
<p>Let's assume that you have created a QSettings object with the organization name MySoft and the application name Star Runner. When you look up a value, up to four locations are searched in that order:</p>
 
156
<ol type="1">
 
157
<li>a user-specific location for the Star Runner application</li>
 
158
<li>a user-spefific location for all applications by MySoft</li>
 
159
<li>a system-wide location for the Star Runner application</li>
 
160
<li>a system-wide location for all applications by MySoft</li>
 
161
</ol>
 
162
<p>On Unix with <a href="winsystem.html#x11">X11</a> and on embedded Linux, these locations are the following files:</p>
 
163
<ol type="1">
 
164
<li><tt>$HOME/.config/MySoft/Star Runner.conf</tt></li>
 
165
<li><tt>$HOME/.config/MySoft.conf</tt></li>
 
166
<li><tt>/etc/xdg/MySoft/Star Runner.conf</tt></li>
 
167
<li><tt>/etc/xdg/MySoft.conf</tt></li>
 
168
</ol>
 
169
<p>On Mac OS X versions 10.2 and 10.3, these files are used:</p>
 
170
<ol type="1">
 
171
<li><tt>$HOME/Library/Preferences/com.MySoft.Star Runner.plist</tt></li>
 
172
<li><tt>$HOME/Library/Preferences/com.MySoft.plist</tt></li>
 
173
<li><tt>/Library/Preferences/com.MySoft.Star Runner.plist</tt></li>
 
174
<li><tt>/Library/Preferences/com.MySoft.plist</tt></li>
 
175
</ol>
 
176
<p>On Windows, the settings are stored in the following registry paths:</p>
 
177
<ol type="1">
 
178
<li><tt>HKEY_CURRENT_USER\Software\MySoft\Star Runner</tt></li>
 
179
<li><tt>HKEY_CURRENT_USER\Software\MySoft</tt></li>
 
180
<li><tt>HKEY_LOCAL_MACHINE\Software\MySoft\Star Runner</tt></li>
 
181
<li><tt>HKEY_LOCAL_MACHINE\Software\MySoft</tt></li>
 
182
</ol>
 
183
<p>If a key cannot be found in the first location, the search goes on in the second location, and so on. This enables you to store system-wide or organization-wide settings and to override them on a per-user or per-application basis. To turn off this mechanism, call setFallbacksEnabled(false).</p>
 
184
<p>Although keys from all four locations are available for reading, only the first file (the user-specific location for the application at hand) is accessible for writing. To write to any of the other files, omit the application name and/or specify <a href="qsettings.html#Scope-enum">QSettings::SystemScope</a> (as opposed to <a href="qsettings.html#Scope-enum">QSettings::UserScope</a>, the default).</p>
 
185
<p>Let's see with an example:</p>
 
186
<pre>&nbsp;       QSettings obj1(&quot;MySoft&quot;, &quot;Star Runner&quot;);
 
187
        QSettings obj2(&quot;MySoft&quot;);
 
188
        QSettings obj3(QSettings::SystemScope, &quot;MySoft&quot;, &quot;Star Runner&quot;);
 
189
        QSettings obj4(QSettings::SystemScope, &quot;MySoft&quot;);</pre>
 
190
<p>The table below summarizes which QSettings objects access which location. &quot;<b>X</b>&quot; means that the location is the main location associated to the QSettings object and is used both for reading and for writing; &quot;o&quot; means that the location is used as a fallback when reading.</p>
 
191
<table align="center" cellpadding="2" cellspacing="1" border="0">
 
192
<tr valign="top" bgcolor="#a2c511"><th>Locations</th><th><tt>obj1</tt></th><th><tt>obj2</tt></th><th><tt>obj3</tt></th><th><tt>obj4</tt></th></tr>
 
193
<tr valign="top" bgcolor="#f0f0f0"><td>1. User, Application</td><td><b>X</b></td><td></td><td></td><td></td></tr>
 
194
<tr valign="top" bgcolor="#e0e0e0"><td>2. User, Organization</td><td>o</td><td><b>X</b></td><td></td><td></td></tr>
 
195
<tr valign="top" bgcolor="#f0f0f0"><td>3. System, Application</td><td>o</td><td></td><td><b>X</b></td><td></td></tr>
 
196
<tr valign="top" bgcolor="#e0e0e0"><td>4. System, Organization</td><td>o</td><td>o</td><td>o</td><td><b>X</b></td></tr>
 
197
</table>
 
198
<p>The beauty of this mechanism is that it works on all platforms supported by Qt and that it still gives you a lot of flexibility, without requiring you to specify any file names or registry paths.</p>
 
199
<p>If you want to use INI files on all platforms instead of the native API, you can pass <a href="qsettings.html#Format-enum">QSettings::IniFormat</a> as the first argument to the QSettings constructor, followed by the scope, the organization name, and the application name:</p>
 
200
<pre>&nbsp;       QSettings settings(QSettings::IniFormat, QSettings::UserScope,
 
201
                           &quot;MySoft&quot;, &quot;Star Runner&quot;);</pre>
 
202
<p>Sometimes you do want to access settings stored in a specific file or registry path. In that case, you can use a constructor that takes a file name (or registry path) and a file format. For example:</p>
 
203
<pre>&nbsp;       QSettings settings(&quot;starrunner.ini&quot;, QSettings::IniFormat);</pre>
 
204
<p>The file format can either be <a href="qsettings.html#Format-enum">QSettings::IniFormat</a> or <a href="qsettings.html#Format-enum">QSettings::NativeFormat</a>. On Mac OS X, the native format is an XML-based format called <i>plist</i>. On Windows, the native format is the Windows registry, and the first argument is a path in the registry rather than a file name, for example:</p>
 
205
<pre>&nbsp;       QSettings settings(&quot;HKEY_CURRENT_USER\\Software\\Microsoft&quot;,
 
206
                           QSettings::NativeFormat);</pre>
 
207
<p>On <a href="winsystem.html#x11">X11</a> and embedded Linux, <a href="qsettings.html#Format-enum">QSettings::IniFormat</a> and <a href="qsettings.html#Format-enum">QSettings::NativeFormat</a> have the same meaning.</p>
 
208
<p>The <a href="tools-settingseditor.html">Settings Editor</a> example lets you experiment with different settings location and with fallbacks turned on or off.</p>
 
209
<a name="restoring-the-state-of-a-gui-application"></a>
 
210
<h3>Restoring the State of a GUI Application</h3>
 
211
<p>QSettings is often used to store the state of a GUI application. The following example will illustrate how to use we will use QSettings to save and restore the geometry of an application's main window.</p>
 
212
<pre>&nbsp;   void MainWindow::writeSettings()
 
213
    {
 
214
        QSettings settings(&quot;Moose Soft&quot;, &quot;Clipper&quot;);
 
215
 
 
216
        settings.beginGroup(&quot;MainWindow&quot;);
 
217
        settings.setValue(&quot;size&quot;, size());
 
218
        settings.setValue(&quot;pos&quot;, pos());
 
219
        settings.endGroup();
 
220
    }
 
221
 
 
222
    void MainWindow::readSettings()
 
223
    {
 
224
        QSettings settings(&quot;Moose Soft&quot;, &quot;Clipper&quot;);
 
225
 
 
226
        settings.beginGroup(&quot;MainWindow&quot;);
 
227
        resize(settings.value(&quot;size&quot;, QSize(400, 400)));
 
228
        move(settings.value(&quot;pos&quot;, QPoint(200, 200)));
 
229
        settings.endGroup();
 
230
    }</pre>
 
231
<p>See <a href="geometry.html">Window Geometry</a> for a discussion on why it is better to call <a href="qwidget.html#size-prop">QWidget::resize</a>() and <a href="qwidget.html#pos-prop">QWidget::move</a>() rather than <a href="qwidget.html#geometry-prop">QWidget::setGeometry</a>() to restore a window's geometry.</p>
 
232
<p>The <tt>readSettings()</tt> and <tt>writeSettings()</tt> functions must be called from the main window's constructor and close event handler as follows:</p>
 
233
<pre>&nbsp;   MainWindow::MainWindow(QWidget *parent)
 
234
        : QMainWindow(parent)
 
235
    {
 
236
        ...
 
237
        readSettings();
 
238
    }
 
239
 
 
240
    void MainWindow::closeEvent(QCloseEvent *event)
 
241
    {
 
242
        if (userReallyWantsToQuit()) {
 
243
            writeSettings();
 
244
            event-&gt;accept();
 
245
        } else {
 
246
            event-&gt;ignore();
 
247
        }
 
248
    }</pre>
 
249
<p>See the <a href="mainwindows-application.html">Application</a> example for a self-contained example that uses QSettings.</p>
 
250
<a name="accessing-settings-from-multiple-threads-or-processes-simultaneously"></a>
 
251
<h3>Accessing Settings from Multiple Threads or Processes Simultaneously</h3>
 
252
<p>QSettings is <a href="threads.html#reentrant">reentrant</a>. This means that you can use distinct QSettings object in different threads simultaneously. This guarantee stands even when the QSettings objects refer to the same files on disk (or to the same entries in the system registry). If a setting is modified through one QSettings object, the change will immediately be visible in any other QSettings objects that operate on the same location and that live in the same process.</p>
 
253
<p>QSettings can safely be used from different processes (which can be different instances of your application running at the same time or different applications altogether) to read and write to the same system locations. It uses a smart merging algorithm to ensure data integrity. Changes performed by another process aren't visible in the current process until <a href="qsettings.html#sync">sync</a>() is called.</p>
 
254
<a name="platform-specific-notes"></a>
 
255
<h3>Platform-Specific Notes</h3>
 
256
<p>While QSettings attempts to smooth over the differences between the different supported platforms, there are still a few differences that you should be aware of when porting your application:</p>
 
257
<ul>
 
258
<li>The Windows system registry has the following limitations: A subkey may not exceed 255 characters, an entry's value may not exceed 16,383 characters, and all the values of a key may not exceed 65,535 characters. One way to work around these limitations is to store the settings using the <a href="qsettings.html#Format-enum">IniFormat</a> instead of the <a href="qsettings.html#Format-enum">NativeFormat</a>.</li>
 
259
<li>On Mac OS X, <a href="qsettings.html#allKeys">allKeys</a>() will return some extra keys for global settings that apply to all applications. These keys can be read using <a href="qsettings.html#value">value</a>() but cannot be changed, only shadowed. Calling setFallbacksEnabled(false) will hide these global settings.</li>
 
260
<li>On Mac OS X, the APIs used by QSettings expect an Internet domain name rather than an organization name. To provide a uniform API, QSettings derives a fake domain name from the organization name (unless the organization name already is a domain name, e.g. OpenOffice.org). The algorithm appends &quot;.com&quot; to the company name and replaces spaces and other illegal characters with hyphens. If you want to specify a different domain name, call <a href="qcoreapplication.html#organizationDomain-prop">QCoreApplication::setOrganizationDomain</a>(), <a href="qcoreapplication.html#organizationName-prop">QCoreApplication::setOrganizationName</a>(), and <a href="qcoreapplication.html#applicationName-prop">QCoreApplication::setApplicationName</a>() in your <tt>main()</tt> function and then use the default QSettings constructor. Another solution is to use preprocessor directives, for example:<pre>&nbsp;   #ifdef Q_WS_MAC
 
261
        QSettings settings(&quot;grenoullelogique.fr&quot;, &quot;Squash&quot;);
 
262
    #else
 
263
        QSettings settings(&quot;Grenoulle Logique&quot;, &quot;Squash&quot;);
 
264
    #endif</pre>
 
265
</li>
 
266
</ul>
 
267
<p>See also <a href="tools-settingseditor.html">Settings Editor Example</a>, <a href="qvariant.html">QVariant</a>, and <a href="qsessionmanager.html">QSessionManager</a>.</p>
 
268
<hr />
 
269
<h2>Member Type Documentation</h2>
 
270
<h3 class="fn"><a name="Format-enum"></a>enum QSettings::Format</h3>
 
271
<p>This enum type specifies the storage format used by <a href="qsettings.html">QSettings</a>.</p>
 
272
<table border="1" cellpadding="2" cellspacing="1" width="100%">
 
273
<tr><th width="25%">Constant</th><th width="15%">Value</th><th width="60%">Description</th></tr>
 
274
<tr><td valign="top"><tt>QSettings::NativeFormat</tt></td><td align="center" valign="top"><tt>0</tt></td><td valign="top">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/<a href="winsystem.html#x11">X11</a>, this means textual configuration files in INI format.</td></tr>
 
275
<tr><td valign="top"><tt>QSettings::IniFormat</tt></td><td align="center" valign="top"><tt>1</tt></td><td valign="top">Store the settings in INI files.</td></tr>
 
276
</table>
 
277
<p>On Unix/<a href="winsystem.html#x11">X11</a>, NativeFormat and IniFormat mean the same thing, except that the file extension is different (<tt>.conf</tt> for NativeFormat, <tt>.ini</tt> for IniFormat).</p>
 
278
<p>The INI file format is a Windows file format that Qt supports on all platforms.</p>
 
279
<h3 class="fn"><a name="Scope-enum"></a>enum QSettings::Scope</h3>
 
280
<p>This enum specifies whether settings are user-specific or shared by all users of the same system.</p>
 
281
<table border="1" cellpadding="2" cellspacing="1" width="100%">
 
282
<tr><th width="25%">Constant</th><th width="15%">Value</th><th width="60%">Description</th></tr>
 
283
<tr><td valign="top"><tt>QSettings::UserScope</tt></td><td align="center" valign="top"><tt>0</tt></td><td valign="top">Store settings in a location specific to the current user (e.g., in the user's home directory).</td></tr>
 
284
<tr><td valign="top"><tt>QSettings::SystemScope</tt></td><td align="center" valign="top"><tt>1</tt></td><td valign="top">Store settings in a global location, so that all users on the same machine access the same set of settings.</td></tr>
 
285
</table>
 
286
<h3 class="fn"><a name="Status-enum"></a>enum QSettings::Status</h3>
 
287
<p>The following status values are possible:</p>
 
288
<table border="1" cellpadding="2" cellspacing="1" width="100%">
 
289
<tr><th width="25%">Constant</th><th width="15%">Value</th><th width="60%">Description</th></tr>
 
290
<tr><td valign="top"><tt>QSettings::NoError</tt></td><td align="center" valign="top"><tt>0</tt></td><td valign="top">No error occurred.</td></tr>
 
291
<tr><td valign="top"><tt>QSettings::AccessError</tt></td><td align="center" valign="top"><tt>1</tt></td><td valign="top">An access error occurred (e.g. trying to write to a read-only file).</td></tr>
 
292
<tr><td valign="top"><tt>QSettings::FormatError</tt></td><td align="center" valign="top"><tt>2</tt></td><td valign="top">A format error occurred (e.g. loading a malformed INI file).</td></tr>
 
293
</table>
 
294
<p>See also <a href="qsettings.html#status">status</a>().</p>
 
295
<hr />
 
296
<h2>Member Function Documentation</h2>
 
297
<h3 class="fn"><a name="QSettings"></a>QSettings::QSettings ( const <a href="qstring.html">QString</a> &amp; <i>organization</i>, const <a href="qstring.html">QString</a> &amp; <i>application</i> = QString(), <a href="qobject.html">QObject</a> * <i>parent</i> = 0 )</h3>
 
298
<p>Constructs a <a href="qsettings.html">QSettings</a> object for accessing settings of the application called <i>application</i> from the organization called <i>organization</i>, and with parent <i>parent</i>.</p>
 
299
<p>Example:</p>
 
300
<pre>&nbsp;   QSettings settings(&quot;Moose Tech&quot;, &quot;Facturo-Pro&quot;);</pre>
 
301
<p>The scope is <a href="qsettings.html#Scope-enum">QSettings::UserScope</a> and the format is <a href="qsettings.html#Format-enum">QSettings::NativeFormat</a>.</p>
 
302
<p>See also <a href="qsettings.html#fallback-mechanism">Fallback Mechanism</a>.</p>
 
303
<h3 class="fn"><a name="QSettings-2"></a>QSettings::QSettings ( <a href="qsettings.html#Scope-enum">Scope</a> <i>scope</i>, const <a href="qstring.html">QString</a> &amp; <i>organization</i>, const <a href="qstring.html">QString</a> &amp; <i>application</i> = QString(), <a href="qobject.html">QObject</a> * <i>parent</i> = 0 )</h3>
 
304
<p>Constructs a <a href="qsettings.html">QSettings</a> object for accessing settings of the application called <i>application</i> from the organization called <i>organization</i>, and with parent <i>parent</i>.</p>
 
305
<p>If <i>scope</i> is <a href="qsettings.html#Scope-enum">QSettings::UserScope</a>, the <a href="qsettings.html">QSettings</a> object searches user-specific settings first, before it searches system-wide settings as a fallback. If <i>scope</i> is <a href="qsettings.html#Scope-enum">QSettings::SystemScope</a>, the <a href="qsettings.html">QSettings</a> object ignores user-specific settings and provides access to system-wide settings.</p>
 
306
<p>The storage format is always <a href="qsettings.html#Format-enum">QSettings::NativeFormat</a>.</p>
 
307
<p>If no application name is given, the <a href="qsettings.html">QSettings</a> object will only access the organization-wide <a href="qsettings.html#fallback-mechanism">locations</a>.</p>
 
308
<h3 class="fn"><a name="QSettings-3"></a>QSettings::QSettings ( <a href="qsettings.html#Format-enum">Format</a> <i>format</i>, <a href="qsettings.html#Scope-enum">Scope</a> <i>scope</i>, const <a href="qstring.html">QString</a> &amp; <i>organization</i>, const <a href="qstring.html">QString</a> &amp; <i>application</i> = QString(), <a href="qobject.html">QObject</a> * <i>parent</i> = 0 )</h3>
 
309
<p>Constructs a <a href="qsettings.html">QSettings</a> object for accessing settings of the application called <i>application</i> from the organization called <i>organization</i>, and with parent <i>parent</i>.</p>
 
310
<p>If <i>scope</i> is <a href="qsettings.html#Scope-enum">QSettings::UserScope</a>, the <a href="qsettings.html">QSettings</a> object searches user-specific settings first, before it searches system-wide settings as a fallback. If <i>scope</i> is <a href="qsettings.html#Scope-enum">QSettings::SystemScope</a>, the <a href="qsettings.html">QSettings</a> object ignores user-specific settings and provides access to system-wide settings.</p>
 
311
<p>If <i>format</i> is <a href="qsettings.html#Format-enum">QSettings::NativeFormat</a>, the native API is used for storing settings. If <i>format</i> is <a href="qsettings.html#Format-enum">QSettings::IniFormat</a>, the INI format is used.</p>
 
312
<p>If no application name is given, the <a href="qsettings.html">QSettings</a> object will only access the organization-wide <a href="qsettings.html#fallback-mechanism">locations</a>.</p>
 
313
<h3 class="fn"><a name="QSettings-4"></a>QSettings::QSettings ( const <a href="qstring.html">QString</a> &amp; <i>fileName</i>, <a href="qsettings.html#Format-enum">Format</a> <i>format</i>, <a href="qobject.html">QObject</a> * <i>parent</i> = 0 )</h3>
 
314
<p>Constructs a <a href="qsettings.html">QSettings</a> object for accessing the settings stored in the file called <i>fileName</i>, with parent <i>parent</i>. If the file doesn't already exist, it is created.</p>
 
315
<p>If <i>format</i> is <a href="qsettings.html#Format-enum">QSettings::NativeFormat</a>, the meaning of <i>fileName</i> depends on the platform. On Unix/<a href="winsystem.html#x11">X11</a>, <i>fileName</i> is the name of an INI file. On Mac OS X, <i>fileName</i> is the name of a .plist file. On Windows, <i>fileName</i> is a path in the system registry.</p>
 
316
<p>If <i>format</i> is <a href="qsettings.html#Format-enum">QSettings::IniFormat</a>, <i>fileName</i> is the name of an INI file.</p>
 
317
<p>See also <a href="qsettings.html#fileName">fileName</a>().</p>
 
318
<h3 class="fn"><a name="QSettings-5"></a>QSettings::QSettings ( <a href="qobject.html">QObject</a> * <i>parent</i> = 0 )</h3>
 
319
<p>Constructs a <a href="qsettings.html">QSettings</a> object for accessing settings of the application and organization set previously with a call to <a href="qcoreapplication.html#organizationName-prop">QCoreApplication::setOrganizationName</a>(), <a href="qcoreapplication.html#organizationDomain-prop">QCoreApplication::setOrganizationDomain</a>(), and <a href="qcoreapplication.html#applicationName-prop">QCoreApplication::setApplicationName</a>().</p>
 
320
<p>The scope is <a href="qsettings.html#Scope-enum">QSettings::UserScope</a> and the format is <a href="qsettings.html#Format-enum">QSettings::NativeFormat</a>.</p>
 
321
<p>The code</p>
 
322
<pre>&nbsp;   QSettings settings(&quot;Moose Soft&quot;, &quot;Facturo-Pro&quot;);</pre>
 
323
<p>is equivalent to</p>
 
324
<pre>&nbsp;   QCoreApplication::setOrganizationName(&quot;Moose Soft&quot;);
 
325
    QCoreApplication::setApplicationName(&quot;Facturo-Pro&quot;);
 
326
    QSettings settings;</pre>
 
327
<p>If <a href="qcoreapplication.html#organizationName-prop">QCoreApplication::setOrganizationName</a>() and <a href="qcoreapplication.html#applicationName-prop">QCoreApplication::setApplicationName</a>() has not been previously called, the <a href="qsettings.html">QSettings</a> object will not be able to read or write any settings, and <a href="qsettings.html#status">status</a>() will return <a href="qsettings.html#Status-enum">AccessError</a>.</p>
 
328
<p>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.</p>
 
329
<p>See also <a href="qcoreapplication.html#organizationName-prop">QCoreApplication::setOrganizationName</a>(), <a href="qcoreapplication.html#organizationDomain-prop">QCoreApplication::setOrganizationDomain</a>(), and <a href="qcoreapplication.html#applicationName-prop">QCoreApplication::setApplicationName</a>().</p>
 
330
<h3 class="fn"><a name="dtor.QSettings"></a>QSettings::~QSettings ()</h3>
 
331
<p>Destroys the <a href="qsettings.html">QSettings</a> object.</p>
 
332
<p>Any unsaved changes will eventually be written to permanent storage.</p>
 
333
<p>See also <a href="qsettings.html#sync">sync</a>().</p>
 
334
<h3 class="fn"><a name="allKeys"></a><a href="qstringlist.html">QStringList</a> QSettings::allKeys () const</h3>
 
335
<p>Returns a list of all keys, including subkeys, that can be read using the <a href="qsettings.html">QSettings</a> object.</p>
 
336
<p>Example:</p>
 
337
<pre>&nbsp;   QSettings settings;
 
338
    settings.setValue(&quot;fridge/color&quot;, Qt::white);
 
339
    settings.setValue(&quot;fridge/size&quot;, QSize(32, 96));
 
340
    settings.setValue(&quot;sofa&quot;, true);
 
341
    settings.setValue(&quot;tv&quot;, false);
 
342
 
 
343
    QStringList keys = settings.allKeys();
 
344
    // keys: [&quot;fridge/color&quot;, &quot;fridge/size&quot;, &quot;sofa&quot;, &quot;tv&quot;]</pre>
 
345
<p>If a group is set using <a href="qsettings.html#beginGroup">beginGroup</a>(), only the keys in the group are returned, without the group prefix:</p>
 
346
<pre>&nbsp;   settings.beginGroup(&quot;fridge&quot;);
 
347
    keys = settings.allKeys();
 
348
    // keys: [&quot;color&quot;, &quot;size&quot;]</pre>
 
349
<p>See also <a href="qsettings.html#childGroups">childGroups</a>() and <a href="qsettings.html#childKeys">childKeys</a>().</p>
 
350
<h3 class="fn"><a name="beginGroup"></a>void QSettings::beginGroup ( const <a href="qstring.html">QString</a> &amp; <i>prefix</i> )</h3>
 
351
<p>Appends <i>prefix</i> to the current group.</p>
 
352
<p>The current group is automatically prepended to all keys specified to <a href="qsettings.html">QSettings</a>. In addition, query functions such as <a href="qsettings.html#childGroups">childGroups</a>(), <a href="qsettings.html#childKeys">childKeys</a>(), and <a href="qsettings.html#allKeys">allKeys</a>() are based on the group. By default, no group is set.</p>
 
353
<p>Groups are useful to avoid typing in the same setting paths over and over. For example:</p>
 
354
<pre>&nbsp;   settings.beginGroup(&quot;mainwindow&quot;);
 
355
    settings.setValue(&quot;size&quot;, win-&gt;size());
 
356
    settings.setValue(&quot;fullScreen&quot;, win-&gt;isFullScreen());
 
357
    settings.endGroup();
 
358
 
 
359
    settings.beginGroup(&quot;outputpanel&quot;);
 
360
    settings.setValue(&quot;visible&quot;, panel-&gt;isVisible());
 
361
    settings.endGroup();</pre>
 
362
<p>This will set the value of three settings:</p>
 
363
<ul>
 
364
<li><tt>mainwindow/size</tt></li>
 
365
<li><tt>mainwindow/fullScreen</tt></li>
 
366
<li><tt>outputpanel/visible</tt></li>
 
367
</ul>
 
368
<p>Call <a href="qsettings.html#endGroup">endGroup</a>() to reset the current group to what it was before the corresponding beginGroup() call. Groups can be nested.</p>
 
369
<p>See also <a href="qsettings.html#endGroup">endGroup</a>() and <a href="qsettings.html#group">group</a>().</p>
 
370
<h3 class="fn"><a name="beginReadArray"></a>int QSettings::beginReadArray ( const <a href="qstring.html">QString</a> &amp; <i>prefix</i> )</h3>
 
371
<p>Adds <i>prefix</i> to the current group and starts reading from an array. Returns the size of the array.</p>
 
372
<p>Example:</p>
 
373
<pre>&nbsp;   struct Login {
 
374
        QString userName;
 
375
        QString password;
 
376
    };
 
377
    QList&lt;Login&gt; logins;
 
378
    ...
 
379
 
 
380
    QSettings settings;
 
381
    int size = settings.beginReadArray(&quot;logins&quot;);
 
382
    for (int i = 0; i &lt; size; ++i) {
 
383
        settings.setArrayIndex(i);
 
384
        Login login;
 
385
        login.userName = settings.value(&quot;userName&quot;);
 
386
        login.password = settings.value(&quot;password&quot;);
 
387
        logins.append(login);
 
388
    }
 
389
    settings.endArray();</pre>
 
390
<p>Use <a href="qsettings.html#beginWriteArray">beginWriteArray</a>() to write the array in the first place.</p>
 
391
<p>See also <a href="qsettings.html#beginWriteArray">beginWriteArray</a>(), <a href="qsettings.html#endArray">endArray</a>(), and <a href="qsettings.html#setArrayIndex">setArrayIndex</a>().</p>
 
392
<h3 class="fn"><a name="beginWriteArray"></a>void QSettings::beginWriteArray ( const <a href="qstring.html">QString</a> &amp; <i>prefix</i>, int <i>size</i> = -1 )</h3>
 
393
<p>Adds <i>prefix</i> to the current group and starts writing an array of size <i>size</i>. If <i>size</i> is -1 (the default), it is automatically determined based on the indexes of the entries written.</p>
 
394
<p>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:</p>
 
395
<pre>&nbsp;   struct Login {
 
396
        QString userName;
 
397
        QString password;
 
398
    };
 
399
    QList&lt;Login&gt; logins;
 
400
    ...
 
401
 
 
402
    QSettings settings;
 
403
    settings.beginWriteArray(&quot;logins&quot;);
 
404
    for (int i = 0; i &lt; logins.size(); ++i) {
 
405
        settings.setArrayIndex(i);
 
406
        settings.setValue(&quot;userName&quot;, list.at(i).userName);
 
407
        settings.setValue(&quot;password&quot;, list.at(i).password);
 
408
    }
 
409
    settings.endArray();</pre>
 
410
<p>The generated keys will have the form</p>
 
411
<ul>
 
412
<li><tt>logins/1/userName</tt></li>
 
413
<li><tt>logins/1/password</tt></li>
 
414
<li><tt>logins/2/userName</tt></li>
 
415
<li><tt>logins/2/password</tt></li>
 
416
<li><tt>logins/3/userName</tt></li>
 
417
<li><tt>logins/3/password</tt></li>
 
418
<li>...</li>
 
419
</ul>
 
420
<p>To read back an array, use <a href="qsettings.html#beginReadArray">beginReadArray</a>().</p>
 
421
<p>See also <a href="qsettings.html#beginReadArray">beginReadArray</a>(), <a href="qsettings.html#endArray">endArray</a>(), and <a href="qsettings.html#setArrayIndex">setArrayIndex</a>().</p>
 
422
<h3 class="fn"><a name="childGroups"></a><a href="qstringlist.html">QStringList</a> QSettings::childGroups () const</h3>
 
423
<p>Returns a list of all key top-level groups that contain keys that can be read using the <a href="qsettings.html">QSettings</a> object.</p>
 
424
<p>Example:</p>
 
425
<pre>&nbsp;   QSettings settings;
 
426
    settings.setValue(&quot;fridge/color&quot;, Qt::white);
 
427
    settings.setValue(&quot;fridge/size&quot;, QSize(32, 96));
 
428
    settings.setValue(&quot;sofa&quot;, true);
 
429
    settings.setValue(&quot;tv&quot;, false);
 
430
 
 
431
    QStringList groups = settings.childGroups();
 
432
    // group: [&quot;fridge&quot;]</pre>
 
433
<p>If a group is set using <a href="qsettings.html#beginGroup">beginGroup</a>(), the first-level keys in that group are returned, without the group prefix.</p>
 
434
<pre>&nbsp;   settings.beginGroup(&quot;fridge&quot;);
 
435
    groups = settings.childGroups();
 
436
    // groups: []</pre>
 
437
<p>You can navigate through the entire setting hierarchy using <a href="qsettings.html#childKeys">childKeys</a>() and childGroups() recursively.</p>
 
438
<p>See also <a href="qsettings.html#childKeys">childKeys</a>() and <a href="qsettings.html#allKeys">allKeys</a>().</p>
 
439
<h3 class="fn"><a name="childKeys"></a><a href="qstringlist.html">QStringList</a> QSettings::childKeys () const</h3>
 
440
<p>Returns a list of all top-level keys that can be read using the <a href="qsettings.html">QSettings</a> object.</p>
 
441
<p>Example:</p>
 
442
<pre>&nbsp;   QSettings settings;
 
443
    settings.setValue(&quot;fridge/color&quot;, Qt::white);
 
444
    settings.setValue(&quot;fridge/size&quot;, QSize(32, 96));
 
445
    settings.setValue(&quot;sofa&quot;, true);
 
446
    settings.setValue(&quot;tv&quot;, false);
 
447
 
 
448
    QStringList keys = settings.childKeys();
 
449
    // keys: [&quot;sofa&quot;, &quot;tv&quot;]</pre>
 
450
<p>If a group is set using <a href="qsettings.html#beginGroup">beginGroup</a>(), the top-level keys in that group are returned, without the group prefix:</p>
 
451
<pre>&nbsp;   settings.beginGroup(&quot;fridge&quot;);
 
452
    keys = settings.childKeys();
 
453
    // keys: [&quot;color&quot;, &quot;size&quot;]</pre>
 
454
<p>You can navigate through the entire setting hierarchy using childKeys() and <a href="qsettings.html#childGroups">childGroups</a>() recursively.</p>
 
455
<p>See also <a href="qsettings.html#childGroups">childGroups</a>() and <a href="qsettings.html#allKeys">allKeys</a>().</p>
 
456
<h3 class="fn"><a name="clear"></a>void QSettings::clear ()</h3>
 
457
<p>Removes all entries in the primary location associated to this <a href="qsettings.html">QSettings</a> object.</p>
 
458
<p>Entries in fallback locations are not removed.</p>
 
459
<p>If you only want to remove the entries in the current <a href="qsettings.html#group">group</a>(), use remove(&quot;&quot;) instead.</p>
 
460
<p>See also <a href="qsettings.html#remove">remove</a>() and <a href="qsettings.html#setFallbacksEnabled">setFallbacksEnabled</a>().</p>
 
461
<h3 class="fn"><a name="contains"></a>bool QSettings::contains ( const <a href="qstring.html">QString</a> &amp; <i>key</i> ) const</h3>
 
462
<p>Returns true if there exists a setting called <i>key</i>; returns false otherwise.</p>
 
463
<p>If a group is set using <a href="qsettings.html#beginGroup">beginGroup</a>(), <i>key</i> is taken to be relative to that group.</p>
 
464
<p>See also <a href="qsettings.html#value">value</a>() and <a href="qsettings.html#setValue">setValue</a>().</p>
 
465
<h3 class="fn"><a name="endArray"></a>void QSettings::endArray ()</h3>
 
466
<p>Closes the array that was started using <a href="qsettings.html#beginReadArray">beginReadArray</a>() or <a href="qsettings.html#beginWriteArray">beginWriteArray</a>().</p>
 
467
<p>See also <a href="qsettings.html#beginReadArray">beginReadArray</a>() and <a href="qsettings.html#beginWriteArray">beginWriteArray</a>().</p>
 
468
<h3 class="fn"><a name="endGroup"></a>void QSettings::endGroup ()</h3>
 
469
<p>Resets the group to what it was before the corresponding <a href="qsettings.html#beginGroup">beginGroup</a>() call.</p>
 
470
<p>Example:</p>
 
471
<pre>&nbsp;   settings.beginGroup(&quot;alpha&quot;);
 
472
    // settings.group() == &quot;alpha&quot;
 
473
 
 
474
    settings.beginGroup(&quot;beta&quot;);
 
475
    // settings.group() == &quot;alpha/beta&quot;
 
476
 
 
477
    settings.endGroup();
 
478
    // settings.group() == &quot;alpha&quot;
 
479
 
 
480
    settings.endGroup();
 
481
    // settings.group() == &quot;&quot;</pre>
 
482
<p>See also <a href="qsettings.html#beginGroup">beginGroup</a>() and <a href="qsettings.html#group">group</a>().</p>
 
483
<h3 class="fn"><a name="fallbacksEnabled"></a>bool QSettings::fallbacksEnabled () const</h3>
 
484
<p>Returns true if fallbacks are enabled; returns false otherwise.</p>
 
485
<p>By default, fallbacks are enabled.</p>
 
486
<p>See also <a href="qsettings.html#setFallbacksEnabled">setFallbacksEnabled</a>().</p>
 
487
<h3 class="fn"><a name="fileName"></a><a href="qstring.html">QString</a> QSettings::fileName () const</h3>
 
488
<p>Returns the path where settings written using this <a href="qsettings.html">QSettings</a> object are stored.</p>
 
489
<p>On Windows, if the format is <a href="qsettings.html#Format-enum">QSettings::NativeFormat</a>, the return value is a system registry path, not a file path.</p>
 
490
<p>See also <a href="qsettings.html#isWritable">isWritable</a>().</p>
 
491
<h3 class="fn"><a name="group"></a><a href="qstring.html">QString</a> QSettings::group () const</h3>
 
492
<p>Returns the current group.</p>
 
493
<p>See also <a href="qsettings.html#beginGroup">beginGroup</a>() and <a href="qsettings.html#endGroup">endGroup</a>().</p>
 
494
<h3 class="fn"><a name="isWritable"></a>bool QSettings::isWritable () const</h3>
 
495
<p>Returns true if settings can be written using this <a href="qsettings.html">QSettings</a> object; returns false otherwise.</p>
 
496
<p>One reason why isWritable() might return false is if <a href="qsettings.html">QSettings</a> operates on a read-only file.</p>
 
497
<p>See also <a href="qsettings.html#fileName">fileName</a>() and <a href="qsettings.html#status">status</a>().</p>
 
498
<h3 class="fn"><a name="remove"></a>void QSettings::remove ( const <a href="qstring.html">QString</a> &amp; <i>key</i> )</h3>
 
499
<p>Removes the setting <i>key</i> and any sub-settings of <i>key</i>.</p>
 
500
<p>Example:</p>
 
501
<pre>&nbsp;   QSettings settings;
 
502
    settings.setValue(&quot;ape&quot;);
 
503
    settings.setValue(&quot;monkey&quot;, 1);
 
504
    settings.setValue(&quot;monkey/sea&quot;, 2);
 
505
    settings.setValue(&quot;monkey/doe&quot;, 4);
 
506
 
 
507
    settings.remove(&quot;monkey&quot;);
 
508
    QStringList keys = settings.allKeys();
 
509
    // keys: [&quot;ape&quot;]</pre>
 
510
<p>Be aware that if one of the fallback locations contains a setting with the same key, that setting will be visible after calling remove().</p>
 
511
<p>If <i>key</i> is an empty string, all keys in the current <a href="qsettings.html#group">group</a>() are removed. For example:</p>
 
512
<pre>&nbsp;   QSettings settings;
 
513
    settings.setValue(&quot;ape&quot;);
 
514
    settings.setValue(&quot;monkey&quot;, 1);
 
515
    settings.setValue(&quot;monkey/sea&quot;, 2);
 
516
    settings.setValue(&quot;monkey/doe&quot;, 4);
 
517
 
 
518
    settings.beginGroup(&quot;monkey&quot;);
 
519
    settings.remove(&quot;&quot;);
 
520
    settings.endGroup();
 
521
 
 
522
    QStringList keys = settings.allKeys();
 
523
    // keys: [&quot;ape&quot;]</pre>
 
524
<p>See also <a href="qsettings.html#setValue">setValue</a>(), <a href="qsettings.html#value">value</a>(), and <a href="qsettings.html#contains">contains</a>().</p>
 
525
<h3 class="fn"><a name="setArrayIndex"></a>void QSettings::setArrayIndex ( int <i>i</i> )</h3>
 
526
<p>Sets the current array index to <i>i</i>. Calls to functions such as <a href="qsettings.html#setValue">setValue</a>(), <a href="qsettings.html#value">value</a>(), <a href="qsettings.html#remove">remove</a>(), and <a href="qsettings.html#contains">contains</a>() will operate on the array entry at that index.</p>
 
527
<p>You must call <a href="qsettings.html#beginReadArray">beginReadArray</a>() or <a href="qsettings.html#beginWriteArray">beginWriteArray</a>() before you can call this function.</p>
 
528
<h3 class="fn"><a name="setFallbacksEnabled"></a>void QSettings::setFallbacksEnabled ( bool <i>b</i> )</h3>
 
529
<p>Sets whether fallbacks are enabled to <i>b</i>.</p>
 
530
<p>By default, fallbacks are enabled.</p>
 
531
<p>See also <a href="qsettings.html#fallbacksEnabled">fallbacksEnabled</a>().</p>
 
532
<h3 class="fn"><a name="setSystemIniPath"></a>void QSettings::setSystemIniPath ( const <a href="qstring.html">QString</a> &amp; <i>dir</i> )&nbsp;&nbsp;<tt> [static]</tt></h3>
 
533
<p>Sets the directory where <a href="qsettings.html">QSettings</a> stores its <a href="qsettings.html#Scope-enum">SystemScope</a> <tt>.ini</tt> files to <i>dir</i>.</p>
 
534
<p>On Unix systems, the default directory is <tt>/etc/xdg</tt> in accordance with FreeDesktop's XDG Base Directory Specification. This default can be changed when compiling Qt by passing the <tt>--sysconfdir</tt> flag to <tt>configure</tt>.</p>
 
535
<p>On Windows, the default directory is <tt>C:\Documents and Settings\All Users\Application Data</tt>.</p>
 
536
<p>A call to this function should precede any instantiations of <a href="qsettings.html">QSettings</a> objects.</p>
 
537
<p>See also <a href="qsettings.html#setUserIniPath">setUserIniPath</a>().</p>
 
538
<h3 class="fn"><a name="setUserIniPath"></a>void QSettings::setUserIniPath ( const <a href="qstring.html">QString</a> &amp; <i>dir</i> )&nbsp;&nbsp;<tt> [static]</tt></h3>
 
539
<p>Sets the directory where <a href="qsettings.html">QSettings</a> stores its <a href="qsettings.html#Scope-enum">UserScope</a> <tt>.ini</tt> files to <i>dir</i>.</p>
 
540
<p>On Unix systems, the default directory is read from the <tt>$XDG_CONFIG_HOME</tt> environment variable. If this variable is empty or unset, <tt>$HOME/.config</tt> is used, in accordance with the FreeDesktop's XDG Base Directory Specification. Calling this function overrides the path specified in <tt>$XDG_CONFIG_HOME</tt>.</p>
 
541
<p>On Windows, the default directory is <tt>C:\Documents and Settings\&lt;username&gt;\Application Data</tt>.</p>
 
542
<p>A call to this function should precede any instantiations of <a href="qsettings.html">QSettings</a> objects.</p>
 
543
<p>See also <a href="qsettings.html#setSystemIniPath">setSystemIniPath</a>().</p>
 
544
<h3 class="fn"><a name="setValue"></a>void QSettings::setValue ( const <a href="qstring.html">QString</a> &amp; <i>key</i>, const <a href="qvariant.html">QVariant</a> &amp; <i>value</i> )</h3>
 
545
<p>Sets the value of setting <i>key</i> to <i>value</i>.</p>
 
546
<p>If the key already exists, the previous value is overwritten.</p>
 
547
<p>Example:</p>
 
548
<pre>&nbsp;   QSettings settings;
 
549
    settings.setValue(&quot;interval&quot;, 30);
 
550
    settings.value(&quot;interval&quot;).toInt();     // returns 30
 
551
 
 
552
    settings.setValue(&quot;interval&quot;, 6.55);
 
553
    settings.value(&quot;interval&quot;).toDouble();  // returns 6.55</pre>
 
554
<p>See also <a href="qsettings.html#value">value</a>(), <a href="qsettings.html#remove">remove</a>(), and <a href="qsettings.html#contains">contains</a>().</p>
 
555
<h3 class="fn"><a name="status"></a><a href="qsettings.html#Status-enum">Status</a> QSettings::status () const</h3>
 
556
<p>Returns a status code indicating the first error that was met by <a href="qsettings.html">QSettings</a>, or <a href="qsettings.html#Status-enum">QSettings::NoError</a> if no error occurred.</p>
 
557
<h3 class="fn"><a name="sync"></a>void QSettings::sync ()</h3>
 
558
<p>Writes any unsaved changes to permanent storage, and reloads any settings that have been changed in the meantime by another application.</p>
 
559
<p>Unless you use <a href="qsettings.html">QSettings</a> as a communication mechanism between different processes, you normally don't need to call this function.</p>
 
560
<h3 class="fn"><a name="value"></a><a href="qvariant.html">QVariant</a> QSettings::value ( const <a href="qstring.html">QString</a> &amp; <i>key</i>, const <a href="qvariant.html">QVariant</a> &amp; <i>defaultValue</i> = QVariant() ) const</h3>
 
561
<p>Returns the value for setting <i>key</i>. If the setting doesn't exist, returns <i>defaultValue</i>.</p>
 
562
<p>If no default value is specified, a default <a href="qvariant.html">QVariant</a> is returned.</p>
 
563
<p>Example:</p>
 
564
<pre>&nbsp;   QSettings settings;
 
565
    settings.setValue(&quot;animal/snake&quot;, 58);
 
566
    settings.value(&quot;animal/snake&quot;, 1024).toInt();   // returns 58
 
567
    settings.value(&quot;animal/zebra&quot;, 1024).toInt();   // returns 1024
 
568
    settings.value(&quot;animal/zebra&quot;).toInt();         // returns 0</pre>
 
569
<p>See also <a href="qsettings.html#setValue">setValue</a>(), <a href="qsettings.html#contains">contains</a>(), and <a href="qsettings.html#remove">remove</a>().</p>
 
570
<p /><address><hr /><div align="center">
 
571
<table width="100%" cellspacing="0" border="0"><tr class="address">
 
572
<td width="30%">Copyright &copy; 2005 <a href="trolltech.html">Trolltech</a></td>
 
573
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
574
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
 
575
</tr></table></div></address></body>
 
576
</html>