📄 qsettings.3qt
字号:
QSettings settings;.br settings.beginGroup( "/MainWindow/Geometry" );.br // read values.br settings.endGroup();.br.fi.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..PPExample 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..PPTo 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"..PPSee also subkeyList()..SH "QString QSettings::group () const"Returns the current key prefix, or a null string if there is no key prefix set..PPSee also beginGroup()..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..PPWhen \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..PPWhen \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..PPWhen reading settings the folders are searched forwards from the first folder (listed below) to the last, returning the first settings found, and ignoring any folders for which the user doesn't have read permission. <ol type=1>.TPHKEY_CURRENT_USER/Software/MyCompany/MyApplication.TPHKEY_LOCAL_MACHINE/Software/MyCompany/MyApplication.TPHKEY_CURRENT_USER/Software/MyApplication.TPHKEY_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.fiThe 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>.TPHKEY_LOCAL_MACHINE/Software/MyCompany/MyApplication.TPHKEY_CURRENT_USER/Software/MyCompany/MyApplication.TPHKEY_LOCAL_MACHINE/Software/MyApplication.TPHKEY_CURRENT_USER/Software/MyApplication If a setting is found in the HKEY_CURRENT_USER space, this setting is overwritten independently of write permissions in the HKEY_LOCAL_MACHINE space..PPWhen \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>.TPINSTALL/etc - where \fCINSTALL\fR is the directory where Qt was installed..TP$HOME/.qt/ - where \fC$HOME\fR is the user's home directory..PPAll 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.fiWill result in a search path of: <ol type=1>.TPINSTALL/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 in the order shown above, writing to the first settings file for which the user has write permission..PPSettings 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)..PPSee also removeSearchPath()..PPExample: chart/chartform.cpp..SH "bool QSettings::readBoolEntry ( const QString & key, bool def = 0, bool * ok = 0 ) const"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..PPSee also readEntry(), readNumEntry(), readDoubleEntry(), writeEntry(), and removeEntry()..SH "double QSettings::readDoubleEntry ( const QString & key, double def = 0, bool * ok = 0 ) const"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..PPSee also readEntry(), readNumEntry(), readBoolEntry(), writeEntry(), and removeEntry()..SH "QString QSettings::readEntry ( const QString & key, const QString & def = QString::null, bool * ok = 0 ) const"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..PPSee also readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), writeEntry(), and removeEntry()..SH "QStringList QSettings::readListEntry ( const QString & key, bool * ok = 0 ) const"Reads the entry specified by \fIkey\fR as a string. If \fIok\fR is not 0, \fI*ok\fR is set to TRUE if the key was read, otherwise \fI*ok\fR is set to FALSE..PPNote 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.PPSee also readEntry(), readDoubleEntry(), readBoolEntry(), writeEntry(), removeEntry(), and QStringList::split()..SH "QStringList QSettings::readListEntry ( const QString & key, const QChar & separator, bool * ok = 0 ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPReads the entry specified by \fIkey\fR as a string. The \fIseparator\fR is used to create a QStringList by calling QStringList::split(\fIseparator\fR, entry). If \fIok\fR is not 0: \fI*ok\fR is set to TRUE if the key was read, otherwise \fI*ok\fR is set to FALSE..PPNote 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.PPSee also readEntry(), readDoubleEntry(), readBoolEntry(), writeEntry(), removeEntry(), and QStringList::split()..SH "int QSettings::readNumEntry ( const QString & key, int def = 0, bool * ok = 0 ) const"Reads the entry specified by \fIkey\fR, and returns an integer, or the default value, \fIdef\fR, if the entry couldn't be read. If \fIok\fR is non-null, *ok is set to TRUE if the key was read, FALSE otherwise..PPSee also readEntry(), readDoubleEntry(), readBoolEntry(), writeEntry(), and removeEntry()..SH "bool QSettings::removeEntry ( const QString & key )"Removes the entry specified by \fIkey\fR..PPReturns TRUE if the entry existed and was removed; otherwise returns FALSE..PPSee 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..PPSee also insertSearchPath()..SH "void QSettings::resetGroup ()"Set the current key prefix to the empty string..SH "void QSettings::setPath ( const QString & domain, const QString & product, Scope scope = Global )"Insert platform-dependent paths from platform-independent information..PPThe \fIdomain\fR should be an Internet domain name controlled by the producer of the software, eg. Trolltech products use "trolltech.com"..PPThe \fIproduct\fR should be the official name of the product..PPThe \fIscope\fR should be QSettings::User for user-specific settings, or QSettings::Global for system-wide settings (generally these will be read-only to many users)..PPNot all information is relevant on all systems (e.g. scoping is currently used only if QSettings accesses the Windows registry)..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..PPExample 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()..PPSee 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..PPIf an error occurs the settings are left unchanged and FALSE is returned; otherwise TRUE is returned..PPSee also readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), and removeEntry()..PPExample: chart/chartform.cpp..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..PPWrites 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..PPIf an error occurs the settings are left unchanged and FALSE is returned; otherwise TRUE is returned..PPSee 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..PPWrites 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..PPIf an error occurs the settings are left unchanged and FALSE is returned; otherwise TRUE is returned..PPSee 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..PPWrites 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..PPIf an error occurs the settings are left unchanged and FALSE is returned; otherwise TRUE is returned..PPSee 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..PPWrites 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..PPIf an error occurs the settings are left unchanged and FALSE is returned; otherwise returns TRUE..PPSee 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..PPWrites 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..PPIf an error occurs the settings are left unchanged and FALSE is returned; otherwise returns TRUE..PPSee 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 COPYRIGHTCopyright 1992-2001 Trolltech AS, http://www.trolltech.com. See thelicense file included in the distribution for a complete licensestatement..SH AUTHORGenerated automatically from the source code..SH BUGSIf 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..PThe definitive Qt documentation is provided in HTML format; it islocated at $QTDIR/doc/html and can be read using Qt Assistant or witha web browser. This man page is provided as a convenience for thoseusers who prefer man pages, although this format is not officiallysupported by Trolltech. .PIf 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 Qtversion (3.1.1).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -