Compatibility Members for QSettings

以下成员源于类 QSettings are part of the Qt compatibility layer. We advise against using them in new code.

公共类型

enum 系统 { Unix, Windows, Mac }

公共函数

QStringList entryList (const QString & key ) const
void insertSearchPath (System system , const QString & path )
bool readBoolEntry (const QString & key , bool defaultValue = false, bool * ok = 0)
double readDoubleEntry (const QString & key , double defaultValue = 0, bool * ok = 0)
QString readEntry (const QString & key , const QString & defaultValue = QString(), bool * ok = 0)
QStringList readListEntry (const QString & key , bool * ok = 0)
QStringList readListEntry (const QString & key , QChar separator , bool * ok = 0)
int readNumEntry (const QString & key , int defaultValue = 0, bool * ok = 0)
bool removeEntry (const QString & key )
void removeSearchPath (System system , const QString & path )
void resetGroup ()
void setPath (const QString & organization , const QString & application , Scope scope = Global)
QStringList subkeyList (const QString & key ) const
bool writeEntry (const QString & key , bool value )
bool writeEntry (const QString & key , double value )
bool writeEntry (const QString & key , int value )
bool writeEntry (const QString & key , const char * value )
bool writeEntry (const QString & key , const QString & value )
bool writeEntry (const QString & key , const QStringList & value )
bool writeEntry (const QString & key , const QStringList & value , QChar separator )

成员类型文档编制

enum QSettings:: 系统

常量 描述
QSettings::Unix 0 Unix systems (X11 and Embedded Linux)
QSettings::Windows 1 Microsoft Windows systems
QSettings::Mac 2 Mac OS X systems

另请参阅 insertSearchPath () 和 removeSearchPath ().

成员函数文档编制

QStringList QSettings:: entryList (const QString & key ) const

Returns a list of all sub-keys of key .

使用 childKeys () 代替。

例如,若有代码像

QSettings settings;
QStringList keys = settings.entryList("cities");
...
					

可以把它重写成

QSettings settings;
settings.beginGroup("cities");
QStringList keys = settings.childKeys();
...
settings.endGroup();
					

void QSettings:: insertSearchPath ( 系统 system , const QString & path )

This function is implemented as a no-op. It is provided for source compatibility with Qt 3. The new QSettings class has no concept of "search path".

bool QSettings:: readBoolEntry (const QString & key , bool defaultValue = false, bool * ok = 0)

返回值为设置 key converted to a bool 。若设置不存在,返回 defaultValue .

ok is not 0, * ok is set to true if the key exists, otherwise * ok 被设为 false。

使用 value () 代替。

例如,若有代码像

bool ok;
bool grid = settings.readBoolEntry("showGrid", true, &ok);
					

可以把它重写成

bool ok = settings.contains("showGrid");
bool grid = settings.value("showGrid", true).toBool();
					

double QSettings:: readDoubleEntry (const QString & key , double defaultValue = 0, bool * ok = 0)

返回值为设置 key converted to a double 。若设置不存在,返回 defaultValue .

ok is not 0, * ok is set to true if the key exists, otherwise * ok 被设为 false。

使用 value () 代替。

例如,若有代码像

bool ok;
double pi = settings.readDoubleEntry("pi", 3.141592, &ok);
					

可以把它重写成

bool ok = settings.contains("pi");
double pi = settings.value("pi", 3.141592).toDouble();
					

QString QSettings:: readEntry (const QString & key , const QString & defaultValue = QString(), bool * ok = 0)

返回值为设置 key converted to a QString 。若设置不存在,返回 defaultValue .

ok is not 0, * ok is set to true if the key exists, otherwise * ok 被设为 false。

使用 value () 代替。

例如,若有代码像

bool ok;
QString str = settings.readEntry("userName", "administrator", &ok);
					

可以把它重写成

bool ok = settings.contains("userName");
QString str = settings.value("userName", "administrator").toString();
					

QStringList QSettings:: readListEntry (const QString & key , bool * ok = 0)

Returns the value of setting key converted to a QStringList .

ok is not 0, * ok is set to true if the key exists, otherwise * ok 被设为 false。

使用 value () 代替。

例如,若有代码像

bool ok;
QStringList list = settings.readListEntry("recentFiles", &ok);
					

可以把它重写成

bool ok = settings.contains("recentFiles");
QStringList list = settings.value("recentFiles").toStringList();
					

QStringList QSettings:: readListEntry (const QString & key , QChar separator , bool * ok = 0)

Returns the value of setting key converted to a QStringList . separator 被忽略。

ok is not 0, * ok is set to true if the key exists, otherwise * ok 被设为 false。

使用 value () 代替。

例如,若有代码像

bool ok;
QStringList list = settings.readListEntry("recentFiles", ":", &ok);
					

可以把它重写成

bool ok = settings.contains("recentFiles");
QStringList list = settings.value("recentFiles").toStringList();
					

int QSettings:: readNumEntry (const QString & key , int defaultValue = 0, bool * ok = 0)

返回值为设置 key converted to an int 。若设置不存在,返回 defaultValue .

ok is not 0, * ok is set to true if the key exists, otherwise * ok 被设为 false。

使用 value () 代替。

例如,若有代码像

bool ok;
int max = settings.readNumEntry("maxConnections", 30, &ok);
					

可以把它重写成

bool ok = settings.contains("maxConnections");
int max = settings.value("maxConnections", 30).toInt();
					

bool QSettings:: removeEntry (const QString & key )

使用 remove () 代替。

void QSettings:: removeSearchPath ( 系统 system , const QString & path )

This function is implemented as a no-op. It is provided for source compatibility with Qt 3. The new QSettings class has no concept of "search path".

void QSettings:: resetGroup ()

Sets the current group to be the empty string.

使用 endGroup () instead (possibly multiple times).

例如,若有代码像

QSettings settings;
settings.beginGroup("mainWindow");
settings.beginGroup("leftPanel");
...
settings.resetGroup();
					

可以把它重写成

QSettings settings;
settings.beginGroup("mainWindow");
settings.beginGroup("leftPanel");
...
settings.endGroup();
settings.endGroup();
					

void QSettings:: setPath (const QString & organization , const QString & application , Scope scope = Global)

Specifies the organization , application ,和 scope to use by the QSettings 对象。

Use the appropriate constructor instead, with QSettings::UserScope 而不是 QSettings::User and QSettings::SystemScope 而不是 QSettings::Global .

例如,若有代码像

QSettings settings;
settings.setPath("twikimaster.com", "Kanooth", QSettings::Global);
					

可以把它重写成

QSettings settings(QSettings::SystemScope, "twikimaster.com", "Kanooth");
					

QStringList QSettings:: subkeyList (const QString & key ) const

Returns a list of all sub-keys of key .

使用 childGroups () 代替。

例如,若有代码像

QSettings settings;
QStringList groups = settings.entryList("cities");
...
					

可以把它重写成

QSettings settings;
settings.beginGroup("cities");
QStringList groups = settings.childKeys();
...
settings.endGroup();
					

bool QSettings:: writeEntry (const QString & key , bool value )

设置值为设置 key to value .

使用 setValue () 代替。

bool QSettings:: writeEntry (const QString & key , double value )

这是重载函数。

bool QSettings:: writeEntry (const QString & key , int value )

这是重载函数。

bool QSettings:: writeEntry (const QString & key , const char * value )

这是重载函数。

bool QSettings:: writeEntry (const QString & key , const QString & value )

这是重载函数。

bool QSettings:: writeEntry (const QString & key , const QStringList & value )

这是重载函数。

bool QSettings:: writeEntry (const QString & key , const QStringList & value , QChar separator )

这是重载函数。

使用 setValue ( key , value ) instead. You don't need separator .