⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qsettings.3qt

📁 linux下GUI编程工具qt的在线连接帮助手册
💻 3QT
📖 第 1 页 / 共 2 页
字号:
'\" t.TH QSettings 3qt "11 October 2001" "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.PP\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 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 will behave as on Unix, and store to text files..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 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.PPA 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.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.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..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..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$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.).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::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..PPExample settings:.PP.nf.br    /MyCompany/MyApplication/background color

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -