1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/tools/qsettings.cpp:67 -->
|
---|
3 | <html>
|
---|
4 | <head>
|
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
6 | <title>QSettings Class</title>
|
---|
7 | <style type="text/css"><!--
|
---|
8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
9 | a:link { color: #004faf; text-decoration: none }
|
---|
10 | a:visited { color: #672967; text-decoration: none }
|
---|
11 | body { background: #ffffff; color: black; }
|
---|
12 | --></style>
|
---|
13 | </head>
|
---|
14 | <body>
|
---|
15 |
|
---|
16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
17 | <tr bgcolor="#E5E5E5">
|
---|
18 | <td valign=center>
|
---|
19 | <a href="index.html">
|
---|
20 | <font color="#004faf">Home</font></a>
|
---|
21 | | <a href="classes.html">
|
---|
22 | <font color="#004faf">All Classes</font></a>
|
---|
23 | | <a href="mainclasses.html">
|
---|
24 | <font color="#004faf">Main Classes</font></a>
|
---|
25 | | <a href="annotated.html">
|
---|
26 | <font color="#004faf">Annotated</font></a>
|
---|
27 | | <a href="groups.html">
|
---|
28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
29 | | <a href="functions.html">
|
---|
30 | <font color="#004faf">Functions</font></a>
|
---|
31 | </td>
|
---|
32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QSettings Class Reference</h1>
|
---|
33 |
|
---|
34 | <p>The QSettings class provides persistent platform-independent application settings.
|
---|
35 | <a href="#details">More...</a>
|
---|
36 | <p><tt>#include <<a href="qsettings-h.html">qsettings.h</a>></tt>
|
---|
37 | <p><a href="qsettings-members.html">List of all member functions.</a>
|
---|
38 | <h2>Public Members</h2>
|
---|
39 | <ul>
|
---|
40 | <li class=fn>enum <a href="#Format-enum"><b>Format</b></a> { Native = 0, Ini }</li>
|
---|
41 | <li class=fn>enum <a href="#System-enum"><b>System</b></a> { Unix = 0, Windows, Mac }</li>
|
---|
42 | <li class=fn>enum <a href="#Scope-enum"><b>Scope</b></a> { User, Global }</li>
|
---|
43 | <li class=fn><a href="#QSettings"><b>QSettings</b></a> ()</li>
|
---|
44 | <li class=fn><a href="#QSettings-2"><b>QSettings</b></a> ( Format format )</li>
|
---|
45 | <li class=fn><a href="#~QSettings"><b>~QSettings</b></a> ()</li>
|
---|
46 | <li class=fn>bool <a href="#writeEntry"><b>writeEntry</b></a> ( const QString & key, bool value )</li>
|
---|
47 | <li class=fn>bool <a href="#writeEntry-2"><b>writeEntry</b></a> ( const QString & key, double value )</li>
|
---|
48 | <li class=fn>bool <a href="#writeEntry-3"><b>writeEntry</b></a> ( const QString & key, int value )</li>
|
---|
49 | <li class=fn>bool <a href="#writeEntry-5"><b>writeEntry</b></a> ( const QString & key, const QString & value )</li>
|
---|
50 | <li class=fn>bool <a href="#writeEntry-6"><b>writeEntry</b></a> ( const QString & key, const QStringList & value )</li>
|
---|
51 | <li class=fn>bool writeEntry ( const QString & key, const QStringList & value, const QChar & separator ) <em>(obsolete)</em></li>
|
---|
52 | <li class=fn>QStringList <a href="#entryList"><b>entryList</b></a> ( const QString & key ) const</li>
|
---|
53 | <li class=fn>QStringList <a href="#subkeyList"><b>subkeyList</b></a> ( const QString & key ) const</li>
|
---|
54 | <li class=fn>QStringList <a href="#readListEntry"><b>readListEntry</b></a> ( const QString & key, bool * ok = 0 ) const</li>
|
---|
55 | <li class=fn>QStringList readListEntry ( const QString & key, const QChar & separator, bool * ok = 0 ) const <em>(obsolete)</em></li>
|
---|
56 | <li class=fn>QString <a href="#readEntry"><b>readEntry</b></a> ( const QString & key, const QString & def = QString::null, bool * ok = 0 ) const</li>
|
---|
57 | <li class=fn>int <a href="#readNumEntry"><b>readNumEntry</b></a> ( const QString & key, int def = 0, bool * ok = 0 ) const</li>
|
---|
58 | <li class=fn>double <a href="#readDoubleEntry"><b>readDoubleEntry</b></a> ( const QString & key, double def = 0, bool * ok = 0 ) const</li>
|
---|
59 | <li class=fn>bool <a href="#readBoolEntry"><b>readBoolEntry</b></a> ( const QString & key, bool def = FALSE, bool * ok = 0 ) const</li>
|
---|
60 | <li class=fn>bool <a href="#removeEntry"><b>removeEntry</b></a> ( const QString & key )</li>
|
---|
61 | <li class=fn>void <a href="#insertSearchPath"><b>insertSearchPath</b></a> ( System s, const QString & path )</li>
|
---|
62 | <li class=fn>void <a href="#removeSearchPath"><b>removeSearchPath</b></a> ( System s, const QString & path )</li>
|
---|
63 | <li class=fn>void <a href="#setPath"><b>setPath</b></a> ( const QString & domain, const QString & product, Scope scope = Global )</li>
|
---|
64 | <li class=fn>void <a href="#beginGroup"><b>beginGroup</b></a> ( const QString & group )</li>
|
---|
65 | <li class=fn>void <a href="#endGroup"><b>endGroup</b></a> ()</li>
|
---|
66 | <li class=fn>void <a href="#resetGroup"><b>resetGroup</b></a> ()</li>
|
---|
67 | <li class=fn>QString <a href="#group"><b>group</b></a> () const</li>
|
---|
68 | </ul>
|
---|
69 | <hr><a name="details"></a><h2>Detailed Description</h2>
|
---|
70 |
|
---|
71 |
|
---|
72 | The QSettings class provides persistent platform-independent application settings.
|
---|
73 | <p>
|
---|
74 |
|
---|
75 |
|
---|
76 | <p> On Unix systems, QSettings uses text files to store settings. On Windows
|
---|
77 | systems, QSettings uses the system registry. On Mac OS X, QSettings uses
|
---|
78 | the Carbon preferences API.
|
---|
79 | <p> Each setting comprises an identifying key and the data associated with
|
---|
80 | the key. A key is a unicode string which consists of <em>two</em> or more
|
---|
81 | subkeys. A subkey is a slash, '/', followed by one or more unicode
|
---|
82 | characters (excluding slashes, newlines, carriage returns and equals,
|
---|
83 | '=', signs). The associated data, called the entry or value, may be a
|
---|
84 | boolean, an integer, a double, a string or a list of strings. Entry
|
---|
85 | strings may contain any unicode characters.
|
---|
86 | <p> If you want to save and restore the entire desktop's settings, i.e.
|
---|
87 | which applications are running, use QSettings to save the settings
|
---|
88 | for each individual application and <a href="qsessionmanager.html">QSessionManager</a> to save the
|
---|
89 | desktop's session.
|
---|
90 | <p> Example settings:
|
---|
91 | <pre>
|
---|
92 | /MyCompany/MyApplication/background color
|
---|
93 | /MyCompany/MyApplication/foreground color
|
---|
94 | /MyCompany/MyApplication/geometry/x
|
---|
95 | /MyCompany/MyApplication/geometry/y
|
---|
96 | /MyCompany/MyApplication/geometry/width
|
---|
97 | /MyCompany/MyApplication/geometry/height
|
---|
98 | /MyCompany/MyApplication/recent files/1
|
---|
99 | /MyCompany/MyApplication/recent files/2
|
---|
100 | /MyCompany/MyApplication/recent files/3
|
---|
101 | </pre>
|
---|
102 |
|
---|
103 | Each line above is a complete key, made up of subkeys.
|
---|
104 | <p> A typical usage pattern for reading settings at application
|
---|
105 | startup:
|
---|
106 | <pre>
|
---|
107 | QSettings settings;
|
---|
108 | settings.<a href="#setPath">setPath</a>( "MyCompany.com", "MyApplication" );
|
---|
109 |
|
---|
110 | <a href="qstring.html">QString</a> bgColor = settings.<a href="#readEntry">readEntry</a>( "/colors/background", "white" );
|
---|
111 | int width = settings.<a href="#readNumEntry">readNumEntry</a>( "/geometry/width", 640 );
|
---|
112 | // ...
|
---|
113 | </pre>
|
---|
114 |
|
---|
115 | <p> A typical usage pattern for saving settings at application exit or
|
---|
116 | 'save preferences':
|
---|
117 | <pre>
|
---|
118 | QSettings settings;
|
---|
119 | settings.<a href="#setPath">setPath</a>( "MyCompany.com", "MyApplication" );
|
---|
120 |
|
---|
121 | settings.<a href="#writeEntry">writeEntry</a>( "/colors/background", bgColor );
|
---|
122 | settings.<a href="#writeEntry">writeEntry</a>( "/geometry/width", width );
|
---|
123 | // ...
|
---|
124 | </pre>
|
---|
125 |
|
---|
126 | <p> A key prefix can be prepended to all keys using <a href="#beginGroup">beginGroup</a>(). The
|
---|
127 | application of the prefix is stopped using <a href="#endGroup">endGroup</a>(). For
|
---|
128 | example:
|
---|
129 | <pre>
|
---|
130 | QSettings settings;
|
---|
131 |
|
---|
132 | settings.<a href="#beginGroup">beginGroup</a>( "/MainWindow" );
|
---|
133 | settings.<a href="#beginGroup">beginGroup</a>( "/Geometry" );
|
---|
134 | int x = settings.<a href="#readEntry">readEntry</a>( "/x" );
|
---|
135 | // ...
|
---|
136 | settings.<a href="#endGroup">endGroup</a>();
|
---|
137 | settings.<a href="#beginGroup">beginGroup</a>( "/Toolbars" );
|
---|
138 | // ...
|
---|
139 | settings.<a href="#endGroup">endGroup</a>();
|
---|
140 | settings.<a href="#endGroup">endGroup</a>();
|
---|
141 | </pre>
|
---|
142 |
|
---|
143 | <p> You can get a list of entry-holding keys by calling <a href="#entryList">entryList</a>(), and
|
---|
144 | a list of key-holding keys using <a href="#subkeyList">subkeyList</a>().
|
---|
145 | <p> <pre>
|
---|
146 | <a href="qstringlist.html">QStringList</a> keys = settings.entryList( "/MyApplication" );
|
---|
147 | // keys contains 'background color' and 'foreground color'.
|
---|
148 |
|
---|
149 | <a href="qstringlist.html">QStringList</a> keys = settings.entryList( "/MyApplication/recent files" );
|
---|
150 | // keys contains '1', '2' and '3'.
|
---|
151 |
|
---|
152 | <a href="qstringlist.html">QStringList</a> subkeys = settings.subkeyList( "/MyApplication" );
|
---|
153 | // subkeys contains 'geometry' and 'recent files'
|
---|
154 |
|
---|
155 | <a href="qstringlist.html">QStringList</a> subkeys = settings.subkeyList( "/MyApplication/recent files" );
|
---|
156 | // subkeys is empty.
|
---|
157 | </pre>
|
---|
158 |
|
---|
159 | <p> Since settings for Windows are stored in the registry there are
|
---|
160 | some size limitations as follows:
|
---|
161 | <ul>
|
---|
162 | <li> A subkey may not exceed 255 characters.
|
---|
163 | <li> An entry's value may not exceed 16,300 characters.
|
---|
164 | <li> All the values of a key (for example, all the 'recent files'
|
---|
165 | subkeys values), may not exceed 65,535 characters.
|
---|
166 | </ul>
|
---|
167 | <p> These limitations are not enforced on Unix or Mac OS X.
|
---|
168 | <p> <b>Warning:</b> Creating multiple, simultaneous instances of QSettings writing
|
---|
169 | to a text file may lead to data loss! This is a known issue which will
|
---|
170 | be fixed in a future release of Qt.
|
---|
171 | <p> <h3> Notes for Mac OS X Applications
|
---|
172 | </h3>
|
---|
173 | <a name="1"></a><p> The location where settings are stored is not formally defined by
|
---|
174 | the CFPreferences API.
|
---|
175 | <p> At the time of writing settings are stored (either on a global or
|
---|
176 | user basis, preferring locally) into a plist file in <tt>$ROOT/System/Library/Preferences</tt> (in XML format). QSettings will
|
---|
177 | create an appropriate plist file (<tt>com.<first group name>.plist</tt>)
|
---|
178 | out of the full path to a key.
|
---|
179 | <p> For further information on CFPreferences see
|
---|
180 | <a href="http://developer.apple.com/documentation/CoreFoundation/Conceptual/CFPreferences/index.html">Apple's Specifications</a>
|
---|
181 | <p> <h3> Notes for Unix Applications
|
---|
182 | </h3>
|
---|
183 | <a name="1-1"></a><p> There is no universally accepted place for storing application
|
---|
184 | settings under Unix. In the examples the settings file will be
|
---|
185 | searched for in the following directories:
|
---|
186 | <ol type=1>
|
---|
187 | <li> <tt>SYSCONF</tt> - the default value is <tt>INSTALL/etc/settings</tt>
|
---|
188 | <li> <tt>/opt/MyCompany/share/etc</tt>
|
---|
189 | <li> <tt>/opt/MyCompany/share/MyApplication/etc</tt>
|
---|
190 | <li> <tt>$HOME/.qt</tt>
|
---|
191 | </ol>
|
---|
192 | When reading settings the files are searched in the order shown
|
---|
193 | above, with later settings overriding earlier settings. Files for
|
---|
194 | which the user doesn't have read permission are ignored. When saving
|
---|
195 | settings QSettings works in the order shown above, writing
|
---|
196 | to the first settings file for which the user has write permission.
|
---|
197 | (<tt>INSTALL</tt> is the directory where Qt was installed. This can be
|
---|
198 | modified by using the configure script's -prefix argument )
|
---|
199 | <p> If you want to put the settings in a particular place in the
|
---|
200 | filesystem you could do this:
|
---|
201 | <pre>
|
---|
202 | settings.insertSearchPath( QSettings::<a href="#System-enum">Unix</a>, "/opt/MyCompany/share" );
|
---|
203 | </pre>
|
---|
204 |
|
---|
205 | <p> But in practice you may prefer not to use a search path for Unix.
|
---|
206 | For example the following code:
|
---|
207 | <pre>
|
---|
208 | settings.writeEntry( "/MyApplication/geometry/width", width );
|
---|
209 | </pre>
|
---|
210 |
|
---|
211 | will end up writing the "geometry/width" setting to the file
|
---|
212 | <tt>$HOME/.qt/myapplicationrc</tt> (assuming that the application is
|
---|
213 | being run by an ordinary user, i.e. not by root).
|
---|
214 | <p> For cross-platform applications you should ensure that the
|
---|
215 | <a href="#sizelimit">Windows size limitations</a> are not exceeded.
|
---|
216 | <p> <b>Warning:</b> QSettings doesn't write the settings until it is destroyed so
|
---|
217 | you should construct the QSettings object on the stack.
|
---|
218 | <p>See also <a href="io.html">Input/Output and Networking</a> and <a href="misc.html">Miscellaneous Classes</a>.
|
---|
219 |
|
---|
220 | <hr><h2>Member Type Documentation</h2>
|
---|
221 | <h3 class=fn><a name="Format-enum"></a>QSettings::Format</h3>
|
---|
222 |
|
---|
223 | <ul>
|
---|
224 | <li><tt>QSettings::Native</tt> - Store the settings in a platform dependent location
|
---|
225 | <li><tt>QSettings::Ini</tt> - Store the settings in a text file
|
---|
226 | </ul>
|
---|
227 | <h3 class=fn><a name="Scope-enum"></a>QSettings::Scope</h3>
|
---|
228 |
|
---|
229 | <ul>
|
---|
230 | <li><tt>QSettings::Global</tt> - Save settings as global as possible
|
---|
231 | <li><tt>QSettings::User</tt> - Save settings in user space
|
---|
232 | </ul>
|
---|
233 | <h3 class=fn><a name="System-enum"></a>QSettings::System</h3>
|
---|
234 |
|
---|
235 | <ul>
|
---|
236 | <li><tt>QSettings::Mac</tt> - Macintosh execution environments
|
---|
237 | <li><tt>QSettings::Unix</tt> - Mac OS X, Unix, Linux and Unix-like execution environments
|
---|
238 | <li><tt>QSettings::Windows</tt> - Windows execution environments
|
---|
239 | </ul>
|
---|
240 | <hr><h2>Member Function Documentation</h2>
|
---|
241 | <h3 class=fn><a name="QSettings"></a>QSettings::QSettings ()
|
---|
242 | </h3>
|
---|
243 | Creates a settings object.
|
---|
244 | <p> Be aware that you must call <a href="#setPath">setPath</a>() or <a href="#insertSearchPath">insertSearchPath</a>() before
|
---|
245 | you can use the QSettings object.
|
---|
246 |
|
---|
247 | <h3 class=fn><a name="QSettings-2"></a>QSettings::QSettings ( <a href="qsettings.html#Format-enum">Format</a> format )
|
---|
248 | </h3>
|
---|
249 | Creates a settings object. If <em>format</em> is 'Ini' the settings will
|
---|
250 | be stored in a text file, using the Unix strategy (see above). If <em>format</em>
|
---|
251 | is 'Native', the settings will be stored in a platform specific way
|
---|
252 | (ie. the Windows registry).
|
---|
253 | <p> Be aware that you must call <a href="#setPath">setPath</a>() or <a href="#insertSearchPath">insertSearchPath</a>() before
|
---|
254 | you can use the QSettings object.
|
---|
255 |
|
---|
256 | <h3 class=fn><a name="~QSettings"></a>QSettings::~QSettings ()
|
---|
257 | </h3>
|
---|
258 | Destroys the settings object. All modifications made to the settings
|
---|
259 | will automatically be saved.
|
---|
260 | <p>
|
---|
261 | <h3 class=fn>void <a name="beginGroup"></a>QSettings::beginGroup ( const <a href="qstring.html">QString</a> & group )
|
---|
262 | </h3>
|
---|
263 | Appends <em>group</em> to the current key prefix.
|
---|
264 | <p> <pre>
|
---|
265 | QSettings settings;
|
---|
266 | settings.<a href="#beginGroup">beginGroup</a>( "/MainWindow" );
|
---|
267 | // read values
|
---|
268 | settings.<a href="#endGroup">endGroup</a>();
|
---|
269 | </pre>
|
---|
270 |
|
---|
271 |
|
---|
272 | <h3 class=fn>void <a name="endGroup"></a>QSettings::endGroup ()
|
---|
273 | </h3>
|
---|
274 | Undo previous calls to <a href="#beginGroup">beginGroup</a>(). Note that a single beginGroup("a/b/c") is undone
|
---|
275 | by a single call to <a href="#endGroup">endGroup</a>().
|
---|
276 | <p> <pre>
|
---|
277 | QSettings settings;
|
---|
278 | settings.<a href="#beginGroup">beginGroup</a>( "/MainWindow/Geometry" );
|
---|
279 | // read values
|
---|
280 | settings.<a href="#endGroup">endGroup</a>();
|
---|
281 | </pre>
|
---|
282 |
|
---|
283 |
|
---|
284 | <h3 class=fn><a href="qstringlist.html">QStringList</a> <a name="entryList"></a>QSettings::entryList ( const <a href="qstring.html">QString</a> & key ) const
|
---|
285 | </h3>
|
---|
286 | Returns a list of the keys which contain entries under <em>key</em>. Does <em>not</em> return any keys that contain subkeys.
|
---|
287 | <p> Example settings:
|
---|
288 | <pre>
|
---|
289 | /MyCompany/MyApplication/background color
|
---|
290 | /MyCompany/MyApplication/foreground color
|
---|
291 | /MyCompany/MyApplication/geometry/x
|
---|
292 | /MyCompany/MyApplication/geometry/y
|
---|
293 | /MyCompany/MyApplication/geometry/width
|
---|
294 | /MyCompany/MyApplication/geometry/height
|
---|
295 | </pre>
|
---|
296 |
|
---|
297 | <pre>
|
---|
298 | <a href="qstringlist.html">QStringList</a> keys = settings.entryList( "/MyCompany/MyApplication" );
|
---|
299 | </pre>
|
---|
300 |
|
---|
301 | <p> In the above example, <tt>keys</tt> will contain 'background color' and
|
---|
302 | 'foreground color'. It will not contain 'geometry' because this key
|
---|
303 | contains subkeys not entries.
|
---|
304 | <p> To access the geometry values, you could either use <a href="#subkeyList">subkeyList</a>()
|
---|
305 | to read the keys then read each entry, or simply read each entry
|
---|
306 | directly by specifying its full key, e.g.
|
---|
307 | "/MyCompany/MyApplication/geometry/y".
|
---|
308 | <p> <p>See also <a href="#subkeyList">subkeyList</a>().
|
---|
309 |
|
---|
310 | <h3 class=fn><a href="qstring.html">QString</a> <a name="group"></a>QSettings::group () const
|
---|
311 | </h3>
|
---|
312 | Returns the current key prefix, or a null string if there is no key prefix set.
|
---|
313 | <p> <p>See also <a href="#beginGroup">beginGroup</a>().
|
---|
314 |
|
---|
315 | <h3 class=fn>void <a name="insertSearchPath"></a>QSettings::insertSearchPath ( <a href="qsettings.html#System-enum">System</a> s, const <a href="qstring.html">QString</a> & path )
|
---|
316 | </h3>
|
---|
317 | Inserts <em>path</em> into the settings search path. The semantics of <em>path</em> depends on the system <em>s</em>. It is usually easier and better to
|
---|
318 | use <a href="#setPath">setPath</a>() instead of this function.
|
---|
319 | <p> When <em>s</em> is <em>Windows</em> and the execution environment is <em>not</em>
|
---|
320 | Windows the function does nothing. Similarly when <em>s</em> is <em>Unix</em> and
|
---|
321 | the execution environment is <em>not</em> Unix the function does nothing.
|
---|
322 | <p> When <em>s</em> is <em>Windows</em>, and the execution environment is Windows, the
|
---|
323 | search path list will be used as the first subfolder of the "Software"
|
---|
324 | folder in the registry.
|
---|
325 | <p> When reading settings the folders are searched forwards from the
|
---|
326 | first folder (listed below) to the last, returning the first
|
---|
327 | settings found, and ignoring any folders for which the user doesn't
|
---|
328 | have read permission.
|
---|
329 | <ol type=1>
|
---|
330 | <li> HKEY_CURRENT_USER/Software/MyCompany/MyApplication
|
---|
331 | <li> HKEY_LOCAL_MACHINE/Software/MyCompany/MyApplication
|
---|
332 | <li> HKEY_CURRENT_USER/Software/MyApplication
|
---|
333 | <li> HKEY_LOCAL_MACHINE/Software/MyApplication
|
---|
334 | </ol>
|
---|
335 | <p> <pre>
|
---|
336 | QSettings settings;
|
---|
337 | settings.<a href="#insertSearchPath">insertSearchPath</a>( QSettings::<a href="#System-enum">Windows</a>, "/MyCompany" );
|
---|
338 | settings.<a href="#writeEntry">writeEntry</a>( "/MyApplication/Tip of the day", TRUE );
|
---|
339 | </pre>
|
---|
340 |
|
---|
341 | The code above will write the subkey "Tip of the day" into the <em>first</em> of the registry folders listed below that is found and for
|
---|
342 | which the user has write permission.
|
---|
343 | <ol type=1>
|
---|
344 | <li> HKEY_LOCAL_MACHINE/Software/MyCompany/MyApplication
|
---|
345 | <li> HKEY_CURRENT_USER/Software/MyCompany/MyApplication
|
---|
346 | <li> HKEY_LOCAL_MACHINE/Software/MyApplication
|
---|
347 | <li> HKEY_CURRENT_USER/Software/MyApplication
|
---|
348 | </ol>
|
---|
349 | If a setting is found in the HKEY_CURRENT_USER space, this setting
|
---|
350 | is overwritten independently of write permissions in the
|
---|
351 | HKEY_LOCAL_MACHINE space.
|
---|
352 | <p> When <em>s</em> is <em>Unix</em>, and the execution environment is Unix, the
|
---|
353 | search path list will be used when trying to determine a suitable
|
---|
354 | filename for reading and writing settings files. By default, there are
|
---|
355 | two entries in the search path:
|
---|
356 | <p> <ol type=1>
|
---|
357 | <li> <tt>SYSCONF</tt> - where <tt>SYSCONF</tt> is a directory specified when
|
---|
358 | configuring Qt; by default it is INSTALL/etc/settings.
|
---|
359 | <li> <tt>$HOME/.qt/</tt> - where <tt>$HOME</tt> is the user's home directory.
|
---|
360 | </ol>
|
---|
361 | <p> All insertions into the search path will go before $HOME/.qt/.
|
---|
362 | For example:
|
---|
363 | <pre>
|
---|
364 | QSettings settings;
|
---|
365 | settings.<a href="#insertSearchPath">insertSearchPath</a>( QSettings::<a href="#System-enum">Unix</a>, "/opt/MyCompany/share/etc" );
|
---|
366 | settings.<a href="#insertSearchPath">insertSearchPath</a>( QSettings::<a href="#System-enum">Unix</a>, "/opt/MyCompany/share/MyApplication/etc" );
|
---|
367 | // ...
|
---|
368 | </pre>
|
---|
369 |
|
---|
370 | Will result in a search path of:
|
---|
371 | <ol type=1>
|
---|
372 | <li> SYSCONF
|
---|
373 | <li> /opt/MyCompany/share/etc
|
---|
374 | <li> /opt/MyCompany/share/MyApplication/etc
|
---|
375 | <li> $HOME/.qt
|
---|
376 | </ol>
|
---|
377 | When reading settings the files are searched in the order shown
|
---|
378 | above, with later settings overriding earlier settings. Files for
|
---|
379 | which the user doesn't have read permission are ignored. When saving
|
---|
380 | settings QSettings works in the order shown above, writing
|
---|
381 | to the first settings file for which the user has write permission.
|
---|
382 | <p> Note that paths in the file system are not created by this
|
---|
383 | function, so they must already exist to be useful.
|
---|
384 | <p> Settings under Unix are stored in files whose names are based on the
|
---|
385 | first subkey of the key (not including the search path). The algorithm
|
---|
386 | for creating names is essentially: lowercase the first subkey, replace
|
---|
387 | spaces with underscores and add 'rc', e.g.
|
---|
388 | <tt>/MyCompany/MyApplication/background color</tt> will be stored in
|
---|
389 | <tt>myapplicationrc</tt> (assuming that <tt>/MyCompany</tt> is part of
|
---|
390 | the search path).
|
---|
391 | <p> <p>See also <a href="#removeSearchPath">removeSearchPath</a>().
|
---|
392 |
|
---|
393 | <p>
|
---|
394 | <p>Example: <a href="canvas-chart-example.html#x2890">chart/chartform.cpp</a>.
|
---|
395 | <h3 class=fn>bool <a name="readBoolEntry"></a>QSettings::readBoolEntry ( const <a href="qstring.html">QString</a> & key, bool def = FALSE, bool * ok = 0 ) const
|
---|
396 | </h3>
|
---|
397 |
|
---|
398 | <p> Reads the entry specified by <em>key</em>, and returns a bool, or the
|
---|
399 | default value, <em>def</em>, if the entry couldn't be read.
|
---|
400 | If <em>ok</em> is non-null, *ok is set to TRUE if the key was read, FALSE
|
---|
401 | otherwise.
|
---|
402 | <p> <p>See also <a href="#readEntry">readEntry</a>(), <a href="#readNumEntry">readNumEntry</a>(), <a href="#readDoubleEntry">readDoubleEntry</a>(), <a href="#writeEntry">writeEntry</a>(), and <a href="#removeEntry">removeEntry</a>().
|
---|
403 |
|
---|
404 | <h3 class=fn>double <a name="readDoubleEntry"></a>QSettings::readDoubleEntry ( const <a href="qstring.html">QString</a> & key, double def = 0, bool * ok = 0 ) const
|
---|
405 | </h3>
|
---|
406 |
|
---|
407 | <p> Reads the entry specified by <em>key</em>, and returns a double, or the
|
---|
408 | default value, <em>def</em>, if the entry couldn't be read.
|
---|
409 | If <em>ok</em> is non-null, *ok is set to TRUE if the key was read, FALSE
|
---|
410 | otherwise.
|
---|
411 | <p> <p>See also <a href="#readEntry">readEntry</a>(), <a href="#readNumEntry">readNumEntry</a>(), <a href="#readBoolEntry">readBoolEntry</a>(), <a href="#writeEntry">writeEntry</a>(), and <a href="#removeEntry">removeEntry</a>().
|
---|
412 |
|
---|
413 | <h3 class=fn><a href="qstring.html">QString</a> <a name="readEntry"></a>QSettings::readEntry ( const <a href="qstring.html">QString</a> & key, const <a href="qstring.html">QString</a> & def = QString::null, bool * ok = 0 ) const
|
---|
414 | </h3>
|
---|
415 |
|
---|
416 | <p> Reads the entry specified by <em>key</em>, and returns a <a href="qstring.html">QString</a>, or the
|
---|
417 | default value, <em>def</em>, if the entry couldn't be read.
|
---|
418 | If <em>ok</em> is non-null, *ok is set to TRUE if the key was read, FALSE
|
---|
419 | otherwise.
|
---|
420 | <p> <p>See also <a href="#readListEntry">readListEntry</a>(), <a href="#readNumEntry">readNumEntry</a>(), <a href="#readDoubleEntry">readDoubleEntry</a>(), <a href="#readBoolEntry">readBoolEntry</a>(), <a href="#writeEntry">writeEntry</a>(), and <a href="#removeEntry">removeEntry</a>().
|
---|
421 |
|
---|
422 | <h3 class=fn><a href="qstringlist.html">QStringList</a> <a name="readListEntry"></a>QSettings::readListEntry ( const <a href="qstring.html">QString</a> & key, bool * ok = 0 ) const
|
---|
423 | </h3>
|
---|
424 |
|
---|
425 | Reads the entry specified by <em>key</em> as a string. If <em>ok</em> is not
|
---|
426 | 0, <em>*ok</em> is set to TRUE if the key was read, otherwise <em>*ok</em> is
|
---|
427 | set to FALSE.
|
---|
428 | <p> Note that if you want to iterate over the list, you should iterate
|
---|
429 | over a copy, e.g.
|
---|
430 | <pre>
|
---|
431 | <a href="qstringlist.html">QStringList</a> list = mySettings.readListEntry( "recentfiles" );
|
---|
432 | QStringList::Iterator it = list.<a href="qvaluelist.html#begin">begin</a>();
|
---|
433 | while( it != list.<a href="qvaluelist.html#end">end</a>() ) {
|
---|
434 | myProcessing( *it );
|
---|
435 | ++it;
|
---|
436 | }
|
---|
437 | </pre>
|
---|
438 |
|
---|
439 | <p> <p>See also <a href="#readEntry">readEntry</a>(), <a href="#readDoubleEntry">readDoubleEntry</a>(), <a href="#readBoolEntry">readBoolEntry</a>(), <a href="#writeEntry">writeEntry</a>(), <a href="#removeEntry">removeEntry</a>(), and <a href="qstringlist.html#split">QStringList::split</a>().
|
---|
440 |
|
---|
441 | <h3 class=fn><a href="qstringlist.html">QStringList</a> <a name="readListEntry-4"></a>QSettings::readListEntry ( const <a href="qstring.html">QString</a> & key, const <a href="qchar.html">QChar</a> & separator, bool * ok = 0 ) const
|
---|
442 | </h3>
|
---|
443 | This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
444 | <p> <b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code.
|
---|
445 | <p> Reads the entry specified by <em>key</em> as a string. The <em>separator</em>
|
---|
446 | is used to create a <a href="qstringlist.html">QStringList</a> by calling <a href="qstringlist.html#split">QStringList::split</a>(<em>separator</em>, entry). If <em>ok</em> is not 0: <em>*ok</em> is set to TRUE
|
---|
447 | if the key was read, otherwise <em>*ok</em> is set to FALSE.
|
---|
448 | <p> <b>Warning:</b> As the documentation states, QStringList::split() will
|
---|
449 | omit empty strings from the list. Because of this, it is
|
---|
450 | impossible to retrieve identical list data with this function. We
|
---|
451 | recommend using the <a href="#readListEntry">readListEntry</a>() and <a href="#writeEntry">writeEntry</a>() overloads
|
---|
452 | that do not take a <em>separator</em> argument.
|
---|
453 | <p> Note that if you want to iterate over the list, you should iterate
|
---|
454 | over a copy, e.g.
|
---|
455 | <pre>
|
---|
456 | <a href="qstringlist.html">QStringList</a> list = mySettings.readListEntry( "size", " " );
|
---|
457 | QStringList::Iterator it = list.<a href="qvaluelist.html#begin">begin</a>();
|
---|
458 | while( it != list.<a href="qvaluelist.html#end">end</a>() ) {
|
---|
459 | myProcessing( *it );
|
---|
460 | ++it;
|
---|
461 | }
|
---|
462 | </pre>
|
---|
463 |
|
---|
464 | <p> <p>See also <a href="#readEntry">readEntry</a>(), <a href="#readDoubleEntry">readDoubleEntry</a>(), <a href="#readBoolEntry">readBoolEntry</a>(), <a href="#writeEntry">writeEntry</a>(), <a href="#removeEntry">removeEntry</a>(), and <a href="qstringlist.html#split">QStringList::split</a>().
|
---|
465 |
|
---|
466 | <h3 class=fn>int <a name="readNumEntry"></a>QSettings::readNumEntry ( const <a href="qstring.html">QString</a> & key, int def = 0, bool * ok = 0 ) const
|
---|
467 | </h3>
|
---|
468 |
|
---|
469 | <p> Reads the entry specified by <em>key</em>, and returns an integer, or the
|
---|
470 | default value, <em>def</em>, if the entry couldn't be read.
|
---|
471 | If <em>ok</em> is non-null, *ok is set to TRUE if the key was read, FALSE
|
---|
472 | otherwise.
|
---|
473 | <p> <p>See also <a href="#readEntry">readEntry</a>(), <a href="#readDoubleEntry">readDoubleEntry</a>(), <a href="#readBoolEntry">readBoolEntry</a>(), <a href="#writeEntry">writeEntry</a>(), and <a href="#removeEntry">removeEntry</a>().
|
---|
474 |
|
---|
475 | <h3 class=fn>bool <a name="removeEntry"></a>QSettings::removeEntry ( const <a href="qstring.html">QString</a> & key )
|
---|
476 | </h3>
|
---|
477 | Removes the entry specified by <em>key</em>.
|
---|
478 | <p> Returns true if the entry was successfully removed; otherwise
|
---|
479 | returns false. Note that removing the last entry in any given
|
---|
480 | folder, will also remove the folder.
|
---|
481 | <p> <p>See also <a href="#readEntry">readEntry</a>() and <a href="#writeEntry">writeEntry</a>().
|
---|
482 |
|
---|
483 | <h3 class=fn>void <a name="removeSearchPath"></a>QSettings::removeSearchPath ( <a href="qsettings.html#System-enum">System</a> s, const <a href="qstring.html">QString</a> & path )
|
---|
484 | </h3>
|
---|
485 | Removes all occurrences of <em>path</em> (using exact matching) from the
|
---|
486 | settings search path for system <em>s</em>. Note that the default search
|
---|
487 | paths cannot be removed.
|
---|
488 | <p> <p>See also <a href="#insertSearchPath">insertSearchPath</a>().
|
---|
489 |
|
---|
490 | <h3 class=fn>void <a name="resetGroup"></a>QSettings::resetGroup ()
|
---|
491 | </h3>
|
---|
492 | Set the current key prefix to the empty string.
|
---|
493 |
|
---|
494 | <h3 class=fn>void <a name="setPath"></a>QSettings::setPath ( const <a href="qstring.html">QString</a> & domain, const <a href="qstring.html">QString</a> & product, <a href="qsettings.html#Scope-enum">Scope</a> scope = Global )
|
---|
495 | </h3>
|
---|
496 | Insert platform-dependent paths from platform-independent information.
|
---|
497 | <p> The <em>domain</em> should be an Internet domain name
|
---|
498 | controlled by the producer of the software, eg. Trolltech products
|
---|
499 | use "trolltech.com".
|
---|
500 | <p> The <em>product</em> should be the official name of the product.
|
---|
501 | <p> The <em>scope</em> should be
|
---|
502 | QSettings::User for user-specific settings, or
|
---|
503 | QSettings::Global for system-wide settings (generally
|
---|
504 | these will be read-only to many users).
|
---|
505 | <p> Not all information is relevant on all systems.
|
---|
506 |
|
---|
507 | <h3 class=fn><a href="qstringlist.html">QStringList</a> <a name="subkeyList"></a>QSettings::subkeyList ( const <a href="qstring.html">QString</a> & key ) const
|
---|
508 | </h3>
|
---|
509 | Returns a list of the keys which contain subkeys under <em>key</em>. Does <em>not</em> return any keys that contain entries.
|
---|
510 | <p> Example settings:
|
---|
511 | <pre>
|
---|
512 | /MyCompany/MyApplication/background color
|
---|
513 | /MyCompany/MyApplication/foreground color
|
---|
514 | /MyCompany/MyApplication/geometry/x
|
---|
515 | /MyCompany/MyApplication/geometry/y
|
---|
516 | /MyCompany/MyApplication/geometry/width
|
---|
517 | /MyCompany/MyApplication/geometry/height
|
---|
518 | /MyCompany/MyApplication/recent files/1
|
---|
519 | /MyCompany/MyApplication/recent files/2
|
---|
520 | /MyCompany/MyApplication/recent files/3
|
---|
521 | </pre>
|
---|
522 |
|
---|
523 | <pre>
|
---|
524 | <a href="qstringlist.html">QStringList</a> keys = settings.subkeyList( "/MyCompany/MyApplication" );
|
---|
525 | </pre>
|
---|
526 |
|
---|
527 | <p> In the above example, <tt>keys</tt> will contain 'geometry' and
|
---|
528 | 'recent files'. It will not contain 'background color' or
|
---|
529 | 'foreground color' because those keys contain entries not
|
---|
530 | subkeys. To get a list of keys that contain entries rather than
|
---|
531 | subkeys use <a href="#entryList">entryList</a>() instead.
|
---|
532 | <p> <b>Warning:</b> In the above example, if QSettings is writing to an Ini file,
|
---|
533 | then a call to
|
---|
534 | <pre> subkeyList("/MyCompany") </pre>
|
---|
535 |
|
---|
536 | will return an empty list. This happens because a key like
|
---|
537 | <pre> /MyCompany/MyApplication/background color </pre>
|
---|
538 |
|
---|
539 | is written to the file <em>"mycompanyrc"</em>, under the section <em>[MyApplication]</em>.
|
---|
540 | This call is therefore a request to list the sections in an ini file, which
|
---|
541 | is not supported in this version of QSettings. This is a known issue which
|
---|
542 | will be fixed in Qt-4.
|
---|
543 | <p> <p>See also <a href="#entryList">entryList</a>().
|
---|
544 |
|
---|
545 | <h3 class=fn>bool <a name="writeEntry"></a>QSettings::writeEntry ( const <a href="qstring.html">QString</a> & key, bool value )
|
---|
546 | </h3>
|
---|
547 | Writes the boolean entry <em>value</em> into key <em>key</em>. The <em>key</em> is
|
---|
548 | created if it doesn't exist. Any previous value is overwritten by <em>value</em>.
|
---|
549 | <p> If an error occurs the settings are left unchanged and FALSE is
|
---|
550 | returned; otherwise TRUE is returned.
|
---|
551 | <p> <b>Warning:</b> On certain platforms, keys are required to contain at least
|
---|
552 | two components (e.g., "/foo/bar"). This limitation does not apply to
|
---|
553 | Qt 4.
|
---|
554 | <p> <p>See also <a href="#readListEntry">readListEntry</a>(), <a href="#readNumEntry">readNumEntry</a>(), <a href="#readDoubleEntry">readDoubleEntry</a>(), <a href="#readBoolEntry">readBoolEntry</a>(), and <a href="#removeEntry">removeEntry</a>().
|
---|
555 |
|
---|
556 | <p>Example: <a href="canvas-chart-example.html#x2891">chart/chartform.cpp</a>.
|
---|
557 | <h3 class=fn>bool <a name="writeEntry-2"></a>QSettings::writeEntry ( const <a href="qstring.html">QString</a> & key, double value )
|
---|
558 | </h3>
|
---|
559 | This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
560 | <p> Writes the double entry <em>value</em> into key <em>key</em>. The <em>key</em> is
|
---|
561 | created if it doesn't exist. Any previous value is overwritten by <em>value</em>.
|
---|
562 | <p> If an error occurs the settings are left unchanged and FALSE is
|
---|
563 | returned; otherwise TRUE is returned.
|
---|
564 | <p> <p>See also <a href="#readListEntry">readListEntry</a>(), <a href="#readNumEntry">readNumEntry</a>(), <a href="#readDoubleEntry">readDoubleEntry</a>(), <a href="#readBoolEntry">readBoolEntry</a>(), and <a href="#removeEntry">removeEntry</a>().
|
---|
565 |
|
---|
566 | <h3 class=fn>bool <a name="writeEntry-3"></a>QSettings::writeEntry ( const <a href="qstring.html">QString</a> & key, int value )
|
---|
567 | </h3>
|
---|
568 | This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
569 | <p> Writes the integer entry <em>value</em> into key <em>key</em>. The <em>key</em> is
|
---|
570 | created if it doesn't exist. Any previous value is overwritten by <em>value</em>.
|
---|
571 | <p> If an error occurs the settings are left unchanged and FALSE is
|
---|
572 | returned; otherwise TRUE is returned.
|
---|
573 | <p> <p>See also <a href="#readListEntry">readListEntry</a>(), <a href="#readNumEntry">readNumEntry</a>(), <a href="#readDoubleEntry">readDoubleEntry</a>(), <a href="#readBoolEntry">readBoolEntry</a>(), and <a href="#removeEntry">removeEntry</a>().
|
---|
574 |
|
---|
575 | <h3 class=fn>bool <a name="writeEntry-5"></a>QSettings::writeEntry ( const <a href="qstring.html">QString</a> & key, const <a href="qstring.html">QString</a> & value )
|
---|
576 | </h3>
|
---|
577 | This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
578 | <p> Writes the string entry <em>value</em> into key <em>key</em>. The <em>key</em> is
|
---|
579 | created if it doesn't exist. Any previous value is overwritten by <em>value</em>. If <em>value</em> is an empty string or a null string the key's
|
---|
580 | value will be an empty string.
|
---|
581 | <p> If an error occurs the settings are left unchanged and FALSE is
|
---|
582 | returned; otherwise TRUE is returned.
|
---|
583 | <p> <p>See also <a href="#readListEntry">readListEntry</a>(), <a href="#readNumEntry">readNumEntry</a>(), <a href="#readDoubleEntry">readDoubleEntry</a>(), <a href="#readBoolEntry">readBoolEntry</a>(), and <a href="#removeEntry">removeEntry</a>().
|
---|
584 |
|
---|
585 | <h3 class=fn>bool <a name="writeEntry-6"></a>QSettings::writeEntry ( const <a href="qstring.html">QString</a> & key, const <a href="qstringlist.html">QStringList</a> & value )
|
---|
586 | </h3>
|
---|
587 | This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
588 | <p> Writes the string list entry <em>value</em> into key <em>key</em>. The <em>key</em>
|
---|
589 | is created if it doesn't exist. Any previous value is overwritten
|
---|
590 | by <em>value</em>.
|
---|
591 | <p> If an error occurs the settings are left unchanged and FALSE is
|
---|
592 | returned; otherwise returns TRUE.
|
---|
593 | <p> <p>See also <a href="#readListEntry">readListEntry</a>(), <a href="#readNumEntry">readNumEntry</a>(), <a href="#readDoubleEntry">readDoubleEntry</a>(), <a href="#readBoolEntry">readBoolEntry</a>(), and <a href="#removeEntry">removeEntry</a>().
|
---|
594 |
|
---|
595 | <h3 class=fn>bool <a name="writeEntry-7"></a>QSettings::writeEntry ( const <a href="qstring.html">QString</a> & key, const <a href="qstringlist.html">QStringList</a> & value, const <a href="qchar.html">QChar</a> & separator )
|
---|
596 | </h3>
|
---|
597 | This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
598 | <p> <b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code.
|
---|
599 | <p> Writes the string list entry <em>value</em> into key <em>key</em>. The <em>key</em>
|
---|
600 | is created if it doesn't exist. Any previous value is overwritten
|
---|
601 | by <em>value</em>. The list is stored as a sequence of strings separated
|
---|
602 | by <em>separator</em> (using <a href="qstringlist.html#join">QStringList::join</a>()), so none of the
|
---|
603 | strings in the list should contain the separator. If the list is
|
---|
604 | empty or null the key's value will be an empty string.
|
---|
605 | <p> <b>Warning:</b> The list should not contain empty or null strings, as
|
---|
606 | <a href="#readListEntry">readListEntry</a>() will use <a href="qstringlist.html#split">QStringList::split</a>() to recreate the
|
---|
607 | list. As the documentation states, QStringList::split() will omit
|
---|
608 | empty strings from the list. Because of this, it is impossible to
|
---|
609 | retrieve identical list data that is stored with this function.
|
---|
610 | We recommend using the <a href="#writeEntry">writeEntry</a>() and readListEntry() overloads
|
---|
611 | that do not take a <em>separator</em> argument.
|
---|
612 | <p> If an error occurs the settings are left unchanged and FALSE is
|
---|
613 | returned; otherwise returns TRUE.
|
---|
614 | <p> <p>See also <a href="#readListEntry">readListEntry</a>(), <a href="#readNumEntry">readNumEntry</a>(), <a href="#readDoubleEntry">readDoubleEntry</a>(), <a href="#readBoolEntry">readBoolEntry</a>(), <a href="#removeEntry">removeEntry</a>(), and <a href="qstringlist.html#join">QStringList::join</a>().
|
---|
615 |
|
---|
616 | <!-- eof -->
|
---|
617 | <hr><p>
|
---|
618 | This file is part of the <a href="index.html">Qt toolkit</a>.
|
---|
619 | Copyright © 1995-2007
|
---|
620 | <a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
|
---|
621 | <table width=100% cellspacing=0 border=0><tr>
|
---|
622 | <td>Copyright © 2007
|
---|
623 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
624 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
625 | </table></div></address></body>
|
---|
626 | </html>
|
---|