1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
|
'\" t
.TH QSettings 3qt "18 March 2002" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2001 Trolltech AS. All rights reserved. See the
.\" license file included in the distribution for a complete license
.\" statement.
.\"
.ad l
.nh
.SH NAME
QSettings \- Persistent platform-independent application settings
.SH SYNOPSIS
\fC#include <qsettings.h>\fR
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "\fBQSettings\fR ()"
.br
.ti -1c
.BI "\fB~QSettings\fR ()"
.br
.ti -1c
.BI "enum \fBSystem\fR { Unix = 0, Windows, Mac }"
.br
.ti -1c
.BI "bool \fBwriteEntry\fR ( const QString & key, bool value )"
.br
.ti -1c
.BI "bool \fBwriteEntry\fR ( const QString & key, double value )"
.br
.ti -1c
.BI "bool \fBwriteEntry\fR ( const QString & key, int value )"
.br
.ti -1c
.BI "bool \fBwriteEntry\fR ( const QString & key, const QString & value )"
.br
.ti -1c
.BI "bool \fBwriteEntry\fR ( const QString & key, const QStringList & value )"
.br
.ti -1c
.BI "bool \fBwriteEntry\fR ( const QString & key, const QStringList & value, const QChar & separator )"
.br
.ti -1c
.BI "QStringList \fBentryList\fR ( const QString & key ) const"
.br
.ti -1c
.BI "QStringList \fBsubkeyList\fR ( const QString & key ) const"
.br
.ti -1c
.BI "QStringList \fBreadListEntry\fR ( const QString & key, bool * ok = 0 )"
.br
.ti -1c
.BI "QStringList \fBreadListEntry\fR ( const QString & key, const QChar & separator, bool * ok = 0 )"
.br
.ti -1c
.BI "QString \fBreadEntry\fR ( const QString & key, const QString & def = QString::null, bool * ok = 0 )"
.br
.ti -1c
.BI "int \fBreadNumEntry\fR ( const QString & key, int def = 0, bool * ok = 0 )"
.br
.ti -1c
.BI "double \fBreadDoubleEntry\fR ( const QString & key, double def = 0, bool * ok = 0 )"
.br
.ti -1c
.BI "bool \fBreadBoolEntry\fR ( const QString & key, bool def = 0, bool * ok = 0 )"
.br
.ti -1c
.BI "bool \fBremoveEntry\fR ( const QString & key )"
.br
.ti -1c
.BI "void \fBinsertSearchPath\fR ( System s, const QString & path )"
.br
.ti -1c
.BI "void \fBremoveSearchPath\fR ( System s, const QString & path )"
.br
.in -1c
.SH DESCRIPTION
The QSettings class provides persistent platform-independent application settings.
.PP
On Unix systems, QSettings uses text files to store settings. On Windows systems, QSettings uses the system registry. On Mac OS X, QSettings will behave as on Unix, and store to text files.
.PP
Each setting comprises an identifying key and the data associated with the key. A key is a unicode string which consists of \fItwo\fR or more subkeys. A subkey is a slash, '/', followed by one or more unicode characters (excluding slashes, newlines, carriage returns and equals, '=', signs). The associated data, called the entry or value, may be a boolean, an integer, a double, a string or a list of strings. Entry strings may contain any unicode characters.
.PP
If you want to save and restore the entire desktop's settings, i.e. which applications are running, use QSettings to save the settings for each individual application and QSessionManager to save the desktop's session.
.PP
Example settings:
.PP
.nf
.br
/MyCompany/MyApplication/background color
.br
/MyCompany/MyApplication/foreground color
.br
/MyCompany/MyApplication/geometry/x
.br
/MyCompany/MyApplication/geometry/y
.br
/MyCompany/MyApplication/geometry/width
.br
/MyCompany/MyApplication/geometry/height
.br
/MyCompany/MyApplication/recent files/1
.br
/MyCompany/MyApplication/recent files/2
.br
/MyCompany/MyApplication/recent files/3
.br
.fi
Each line above is a complete key, made up of subkeys.
.PP
A typical usage pattern for application startup:
.PP
.nf
.br
QSettings settings;
.br
settings.insertSearchPath( QSettings::Windows, "/MyCompany" );
.br
// No search path needed for Unix; see notes further on.
.br
// Use default values if the keys don't exist
.br
QString bgColor = settings.readEntry( "/MyApplication/background color", "white" );
.br
int width = settings.readNumEntry( "/MyApplication/geometry/width", 640 );
.br
// ...
.br
.fi
.PP
A typical usage pattern for application exit or 'save preferences':
.PP
.nf
.br
QSettings settings;
.br
settings.insertSearchPath( QSettings::Windows, "/MyCompany" );
.br
// No search path needed for Unix; see notes further on.
.br
settings.writeEntry( "/MyApplication/background color", bgColor );
.br
settings.writeEntry( "/MyApplication/geometry/width", width );
.br
// ...
.br
.fi
.PP
You can get a list of entry-holding keys by calling entryList(), and a list of key-holding keys using subkeyList().
.PP
.nf
.br
QStringList keys = entryList( "/MyApplication" );
.br
// keys contains 'background color' and 'foreground color'.
.br
.br
QStringList keys = entryList( "/MyApplication/recent files" );
.br
// keys contains '1', '2' and '3'.
.br
.br
QStringList subkeys = subkeyList( "/MyApplication" );
.br
// subkeys contains 'geometry' and 'recent files'
.br
.br
QStringList subkeys = subkeyList( "/MyApplication/recent files" );
.br
// subkeys is empty.
.br
.fi
.PP
If you wish to use a different search path call insertSearchPath() as often as necessary to add your preferred paths. Call removeSearchPath() to remove any unwanted paths.
.PP
Since settings for Windows are stored in the registry there are size limits as follows:
.TP
A subkey may not exceed 255 characters.
.TP
An entry's value may not exceed 16,300 characters.
.TP
All the values of a key (for example, all the 'recent files' subkeys values), may not exceed 65,535 characters.
.PP
These limitations are not enforced on Unix.
.SH "Notes for Unix Applications"
There is no universally accepted place for storing application settings under Unix. In the examples the settings file will be searched for in the following directories: <ol type=1>
.TP
$QT_INSTALL_PREFIX/etc/settings
.TP
/opt/MyCompany/share/etc
.TP
/opt/MyCompany/share/MyApplication/etc
.TP
$HOME/.qt When reading settings the files are searched in the order shown above, with later settings overriding earlier settings. Files for which the user doesn't have read permission are ignored. When saving settings QSettings works forwards in the order shown above writing to the first settings file for which the user has write permission. ($QT_INSTALL_PREFIX is the directory where Qt was installed. This can be modified by using the configure script's -prefix argument)
.PP
If you want to put the settings in a particular place in the filesystem you could do this:
.PP
.nf
.br
settings.insertSearchPath( QSettings::Unix, "/opt/MyCompany/share" );
.br
.fi
.PP
But in practice you may prefer not to use a search path for Unix. For example the following code:
.PP
.nf
.br
settings.writeEntry( "/MyApplication/geometry/width", width );
.br
.fi
will end up writing the "geometry/width" setting to the file \fC$HOME/.qt/myapplicationrc\fR (assuming that the application is being run by an ordinary user, i.e. not by root).
.PP
For cross-platform applications you should ensure that the Windows size limitations are not exceeded.
.PP
See also Input/Output and Networking and Miscellaneous Classes.
.SS "Member Type Documentation"
.SH "QSettings::System"
.TP
\fCQSettings::Mac\fR - Macintosh execution environments
.TP
\fCQSettings::Unix\fR - Mac OS X, Unix, Linux and Unix-like execution environments
.TP
\fCQSettings::Windows\fR - Windows execution environments
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QSettings::QSettings ()"
Creates a settings object.
.SH "QSettings::~QSettings ()"
Destroys the settings object. All modifications made to the settings will automatically be saved.
.SH "QStringList QSettings::entryList ( const QString & key ) const"
Returns a list of the keys which contain entries under \fIkey\fR. Does \fInot\fR return any keys that contain keys.
.PP
Example settings:
.PP
.nf
.br
/MyCompany/MyApplication/background color
.br
/MyCompany/MyApplication/foreground color
.br
/MyCompany/MyApplication/geometry/x
.br
/MyCompany/MyApplication/geometry/y
.br
/MyCompany/MyApplication/geometry/width
.br
/MyCompany/MyApplication/geometry/height
.br
.fi
.PP
.nf
.br
QStringList keys = entryList( "/MyCompany/MyApplication" );
.br
.fi
\fCkeys\fR contains 'background color' and 'foreground color'. It does not contain 'geometry' because this key contains keys not entries.
.PP
To access the geometry values could either use subkeyList() to read the keys and then read each entry, or simply read each entry directly by specifying its full key, e.g." /MyCompany/MyApplication/geometry/y".
.PP
See also subkeyList().
.SH "void QSettings::insertSearchPath ( System s, const QString & path )"
Inserts \fIpath\fR into the settings search path. The semantics of \fIpath\fR depends on the system \fIs\fR.
.PP
When \fIs\fR is \fIWindows\fR and the execution environment is \fInot\fR Windows the function does nothing. Similarly when \fIs\fR is \fIUnix\fR and the execution environment is \fInot\fR Unix the function does nothing.
.PP
When \fIs\fR is \fIWindows\fR, and the execution environment is Windows, the search path list will be used as the first subfolder of the "Software" folder in the registry.
.PP
When reading settings the folders are searched forwards from the first folder (listed below) to the last, with later settings overriding settings found earlier, and ignoring any folders for which the user doesn't have read permission. <ol type=1>
.TP
HKEY_CURRENT_USER/Software/MyCompany/MyApplication
.TP
HKEY_CURRENT_USER/Software/MyApplication
.TP
HKEY_LOCAL_MACHINE/Software/MyCompany/MyApplication
.TP
HKEY_LOCAL_MACHINE/Software/MyApplication
.PP
.nf
.br
QSettings settings;
.br
settings.insertSearchPath( QSettings::Windows, "/MyCompany" );
.br
settings.writeEntry( "/MyApplication/Tip of the day", TRUE );
.br
.fi
The code above will write the subkey "Tip of the day" into the \fIfirst\fR of the registry folders listed below that is found and for which the user has write permission. <ol type=1>
.TP
HKEY_LOCAL_MACHINE/Software/MyApplication
.TP
HKEY_LOCAL_MACHINE/Software/MyCompany/MyApplication
.TP
HKEY_CURRENT_USER/Software/MyApplication
.TP
HKEY_CURRENT_USER/Software/MyCompany/MyApplication
.PP
When \fIs\fR is \fIUnix\fR, and the execution environment is Unix, the search path list will be used when trying to determine a suitable filename for reading and writing settings files. By default, there are two entries in the search path:
.PP
<ol type=1>
.TP
$QTDIR/etc - where $QTDIR is the directory where Qt was installed.
.TP
$HOME/.qt/ - where $HOME is the user's home directory.
.PP
All insertions into the search path will go before $HOME/.qt/. For example:
.PP
.nf
.br
QSettings settings;
.br
settings.insertSearchPath( QSettings::Unix, "/opt/MyCompany/share/etc" );
.br
settings.insertSearchPath( QSettings::Unix, "/opt/MyCompany/share/MyApplication/etc" );
.br
// ...
.br
.fi
Will result in a search path of: <ol type=1>
.TP
$QTDIR/etc
.TP
/opt/MyCompany/share/etc
.TP
/opt/MyCompany/share/MyApplication/etc
.TP
$HOME/.qt When reading settings the files are searched in the order shown above, with later settings overriding earlier settings. Files for which the user doesn't have read permission are ignored. When saving settings QSettings works forwards in the order shown above writing to the first settings file for which the user has write permission. ($QTDIR is the directory where Qt was installed.)
.PP
Settings under Unix are stored in files whose names are based on the first subkey of the key (not including the search path). The algorithm for creating names is essentially: lowercase the first subkey, replace spaces with underscores and add 'rc', e.g. \fC/MyCompany/MyApplication/background color\fR will be stored in \fCmyapplicationrc\fR (assuming that \fC/MyCompany\fR is part of the search path).
.PP
See also removeSearchPath().
.SH "bool QSettings::readBoolEntry ( const QString & key, bool def = 0, bool * ok = 0 )"
Reads the entry specified by \fIkey\fR, and returns a bool, or the default value, \fIdef\fR, if the entry couldn't be read. If \fIok\fR is non-null, *ok is set to TRUE if the key was read, FALSE otherwise.
.PP
See also readEntry(), readNumEntry(), readDoubleEntry(), writeEntry() and removeEntry().
.SH "double QSettings::readDoubleEntry ( const QString & key, double def = 0, bool * ok = 0 )"
Reads the entry specified by \fIkey\fR, and returns a double, or the default value, \fIdef\fR, if the entry couldn't be read. If \fIok\fR is non-null, *ok is set to TRUE if the key was read, FALSE otherwise.
.PP
See also readEntry(), readNumEntry(), readBoolEntry(), writeEntry() and removeEntry().
.SH "QString QSettings::readEntry ( const QString & key, const QString & def = QString::null, bool * ok = 0 )"
Reads the entry specified by \fIkey\fR, and returns a QString, or the default value, \fIdef\fR, if the entry couldn't be read. If \fIok\fR is non-null, *ok is set to TRUE if the key was read, FALSE otherwise.
.PP
See also readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), writeEntry() and removeEntry().
.SH "QStringList QSettings::readListEntry ( const QString & key, bool * ok = 0 )"
Reads the entry specified by \fIkey\fR as a string. If \fIok\fR is non-null, *ok is set to TRUE if the key was read, FALSE otherwise.
.PP
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
.PP
.nf
.br
QStringList list = mySettings.readListEntry( "recentfiles" );
.br
QStringList::Iterator it = list.begin();
.br
while( it != list.end() ) {
.br
myProcessing( *it );
.br
++it;
.br
}
.br
.fi
.PP
See also readEntry(), readDoubleEntry(), readBoolEntry(), writeEntry(), removeEntry() and QStringList::split().
.SH "QStringList QSettings::readListEntry ( const QString & key, const QChar & separator, bool * ok = 0 )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Reads the entry specified by \fIkey\fR as a string. The \fIseparator\fR is used to create a QStringList by calling QStringList::split(\fIseparator\fR, entry). If \fIok\fR is non-null, *ok is set to TRUE if the key was read, FALSE otherwise.
.PP
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
.PP
.nf
.br
QStringList list = mySettings.readListEntry( "size", " " );
.br
QStringList::Iterator it = list.begin();
.br
while( it != list.end() ) {
.br
myProcessing( *it );
.br
++it;
.br
}
.br
.fi
.PP
See also readEntry(), readDoubleEntry(), readBoolEntry(), writeEntry(), removeEntry() and QStringList::split().
.SH "int QSettings::readNumEntry ( const QString & key, int def = 0, bool * ok = 0 )"
Reads the entry specified by \fIkey\fR, and returns an integer, or the default value, \fIdef\fR, if the entry couldn't be read. If \fIok\fR is non-null, *ok is set to TRUE if the key was read, FALSE otherwise.
.PP
See also readEntry(), readDoubleEntry(), readBoolEntry(), writeEntry() and removeEntry().
.SH "bool QSettings::removeEntry ( const QString & key )"
Removes the entry specified by \fIkey\fR.
.PP
Returns TRUE if the entry existed and was removed; otherwise returns FALSE.
.PP
See also readEntry() and writeEntry().
.SH "void QSettings::removeSearchPath ( System s, const QString & path )"
Removes all occurrences of \fIpath\fR (using exact matching) from the settings search path for system \fIs\fR. Note that the default search paths cannot be removed.
.PP
See also insertSearchPath().
.SH "QStringList QSettings::subkeyList ( const QString & key ) const"
Returns a list of the keys which contain keys under \fIkey\fR. Does \fInot\fR return any keys that contain entries.
.PP
Example settings:
.PP
.nf
.br
/MyCompany/MyApplication/background color
.br
/MyCompany/MyApplication/foreground color
.br
/MyCompany/MyApplication/geometry/x
.br
/MyCompany/MyApplication/geometry/y
.br
/MyCompany/MyApplication/geometry/width
.br
/MyCompany/MyApplication/geometry/height
.br
/MyCompany/MyApplication/recent files/1
.br
/MyCompany/MyApplication/recent files/2
.br
/MyCompany/MyApplication/recent files/3
.br
.fi
.PP
.nf
.br
QStringList keys = subkeyList( "/MyCompany/MyApplication" );
.br
.fi
\fCkeys\fR contains 'geometry' and 'recent files'. It does not contain 'background color' or 'foreground color' because they are keys which contain entries not keys. To get a list of keys that have values rather than subkeys use entryList().
.PP
See also entryList().
.SH "bool QSettings::writeEntry ( const QString & key, bool value )"
Writes the boolean entry \fIvalue\fR into key \fIkey\fR. The \fIkey\fR is created if it doesn't exist. Any previous value is overwritten by \fIvalue\fR.
.PP
If an error occurs the settings are left unchanged and FALSE is returned; otherwise TRUE is returned.
.PP
See also readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry() and removeEntry().
.SH "bool QSettings::writeEntry ( const QString & key, double value )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Writes the double entry \fIvalue\fR into key \fIkey\fR. The \fIkey\fR is created if it doesn't exist. Any previous value is overwritten by \fIvalue\fR.
.PP
If an error occurs the settings are left unchanged and FALSE is returned; otherwise TRUE is returned.
.PP
See also readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry() and removeEntry().
.SH "bool QSettings::writeEntry ( const QString & key, int value )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Writes the integer entry \fIvalue\fR into key \fIkey\fR. The \fIkey\fR is created if it doesn't exist. Any previous value is overwritten by \fIvalue\fR.
.PP
If an error occurs the settings are left unchanged and FALSE is returned; otherwise TRUE is returned.
.PP
See also readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry() and removeEntry().
.SH "bool QSettings::writeEntry ( const QString & key, const QString & value )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Writes the string entry \fIvalue\fR into key \fIkey\fR. The \fIkey\fR is created if it doesn't exist. Any previous value is overwritten by \fIvalue\fR. If \fIvalue\fR is an empty string or a null string the key's value will be an empty string.
.PP
If an error occurs the settings are left unchanged and FALSE is returned; otherwise TRUE is returned.
.PP
See also readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry() and removeEntry().
.SH "bool QSettings::writeEntry ( const QString & key, const QStringList & value )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Writes the string list entry \fIvalue\fR into key \fIkey\fR. The \fIkey\fR is created if it doesn't exist. Any previous value is overwritten by \fIvalue\fR.
.PP
If an error occurs the settings are left unchanged and FALSE is returned; otherwise TRUE is returned.
.PP
See also readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry() and removeEntry().
.SH "bool QSettings::writeEntry ( const QString & key, const QStringList & value, const QChar & separator )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Writes the string list entry \fIvalue\fR into key \fIkey\fR. The \fIkey\fR is created if it doesn't exist. Any previous value is overwritten by \fIvalue\fR. The list is stored as a sequence of strings separated by \fIseparator\fR, so none of the strings in the list should contain the separator. If the list is empty or null the key's value will be an empty string.
.PP
If an error occurs the settings are left unchanged and FALSE is returned; otherwise TRUE is returned.
.PP
See also readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry() and removeEntry().
.SH "SEE ALSO"
.BR http://doc.trolltech.com/qsettings.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2001 Trolltech AS, http://www.trolltech.com. See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive Qt documentation is provided in HTML format; it is
located at $QTDIR/doc/html and can be read using Qt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech.
.P
If you find errors in this manual page, please report them to
.BR qt-bugs@trolltech.com .
Please include the name of the manual page (qsettings.3qt) and the Qt
version (3.0.3).
|