📄 qsettings.3qt
字号:
'\" t.TH QSettings 3qt "9 December 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 NAMEQSettings \- Persistent platform-independent application settings.SH SYNOPSIS\fC#include <qsettings.h>\fR.PP.SS "Public Members".in +1c.ti -1c.BI "enum \fBFormat\fR { Native = 0, Ini }".br.ti -1c.BI "enum \fBSystem\fR { Unix = 0, Windows, Mac }".br.ti -1c.BI "enum \fBScope\fR { User, Global }".br.ti -1c.BI "\fBQSettings\fR ()".br.ti -1c.BI "\fBQSettings\fR ( Format format )".br.ti -1c.BI "\fB~QSettings\fR ()".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 ) const".br.ti -1c.BI "QStringList \fBreadListEntry\fR ( const QString & key, const QChar & separator, bool * ok = 0 ) const".br.ti -1c.BI "QString \fBreadEntry\fR ( const QString & key, const QString & def = QString::null, bool * ok = 0 ) const".br.ti -1c.BI "int \fBreadNumEntry\fR ( const QString & key, int def = 0, bool * ok = 0 ) const".br.ti -1c.BI "double \fBreadDoubleEntry\fR ( const QString & key, double def = 0, bool * ok = 0 ) const".br.ti -1c.BI "bool \fBreadBoolEntry\fR ( const QString & key, bool def = 0, bool * ok = 0 ) const".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.ti -1c.BI "void \fBsetPath\fR ( const QString & domain, const QString & product, Scope scope = Global )".br.ti -1c.BI "void \fBbeginGroup\fR ( const QString & group )".br.ti -1c.BI "void \fBendGroup\fR ()".br.ti -1c.BI "void \fBresetGroup\fR ()".br.ti -1c.BI "QString \fBgroup\fR () const".br.in -1c.SH DESCRIPTIONThe QSettings class provides persistent platform-independent application settings..PPOn Unix systems, QSettings uses text files to store settings. On Windows systems, QSettings uses the system registry. On Mac OS X, QSettings uses the Carbon preferences API..PPEach 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..PPIf 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..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.fiEach line above is a complete key, made up of subkeys..PPA typical usage pattern for reading application startup:.PP.nf.br QSettings settings;.br settings.setPath( "MyCompany.com", "MyApplication" );.br.br QString bgColor = settings.readEntry( "/background color", "white" );.br int width = settings.readNumEntry( "/geometry/width", 640 );.br // ....br.fi.PPA typical usage pattern for application exit or 'save preferences':.PP.nf.br QSettings settings;.br settings.setPath( "MyCompany.com", "MyApplication" );.br.br settings.writeEntry( "/background color", bgColor );.br settings.writeEntry( "/geometry/width", width );.br // ....br.fi.PPQSettings can build a key prefix that is prepended to all keys. To build the key prefix, use beginGroup() and endGroup()..PP.nf.br QSettings settings;.br.br settings.beginGroup( "/MainWindow" );.br settings.beginGroup( "/Geometry" );.br int x = settings.readEntry( "/x" );.br // ....br settings.endGroup();.br settings.beginGroup( "/Toolbars" );.br // ....br settings.endGroup();.br settings.endGroup();.br.fi.PPYou 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.PPSince settings for Windows are stored in the registry there are size limits as follows:.TPA subkey may not exceed 255 characters..TPAn entry's value may not exceed 16,300 characters..TPAll the values of a key (for example, all the 'recent files' subkeys values), may not exceed 65,535 characters..PPThese limitations are not enforced on Unix or Mac OS X..PPIf 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..SH "Notes for Mac OS X Applications"Internal to the CFPreferences API it is not defined (for Mac OS 9 support) where the settings will ultimitely be stored. However, at the time of this writing the settings will be stored (either on a global or user basis, preferring locally) into a plist file in $ROOT/System/Library/Preferences (in XML format). QSettings will create an appropriate plist file (com.<first group name>.plist) out of the full path to a key..PPFor further information on CFPreferences see also Apple's Specifications.SH "Notes for Unix Applications"There is no universally accepted place for storing application settings under Unix. In the examples the settings file will be searched for in the following directories: <ol type=1>.TPINSTALL/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 in the order shown above, writing to the first settings file for which the user has write permission. (\fCINSTALL\fR is the directory where Qt was installed. This can be modified by using the configure script's -prefix argument ).PPIf 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.PPBut 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.fiwill 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)..PPFor cross-platform applications you should ensure that the Windows size limitations are not exceeded..PPSee also Input/Output and Networking and Miscellaneous Classes..SS "Member Type Documentation".SH "QSettings::Format".TP\fCQSettings::Native\fR - Store the settings in a platform dependent location.TP\fCQSettings::Ini\fR - Store the settings in a text file.SH "QSettings::Scope".TP\fCQSettings::Global\fR - Save settings as global as possible.TP\fCQSettings::User\fR - Save settings in user space.SH "QSettings::System".TP\fCQSettings::Mac\fR - Macintosh execution environments.TP\fCQSettings::Unix\fR - Mac OS X, Unix, Linux and Unix-like execution environments.TP\fCQSettings::Windows\fR - Windows execution environments.SH MEMBER FUNCTION DOCUMENTATION.SH "QSettings::QSettings ()"Creates a settings object..SH "QSettings::QSettings ( Format format )"Creates a settings object. If \fIformat\fR is 'Ini' the settings will be stored in a text file, using the Unix strategy (see above). If \fIformat\fR is 'Native', the settings will be stored in a platform specific way (ie. the Windows registry)..SH "QSettings::~QSettings ()"Destroys the settings object. All modifications made to the settings will automatically be saved..SH "void QSettings::beginGroup ( const QString & group )"Appends \fIgroup\fR to the current key prefix..PP.nf.br QSettings settings;.br settings.beginGroup( "/MainWindow" );.br // read values.br settings.endGroup();.br.fi.SH "void QSettings::endGroup ()"Undo previous calls to beginGroup(). Note that a single beginGroup("a/b/c") is undone by a single call to endGroup()..PP.nf.br
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -