QMetaEnum 類

QMetaEnum 類提供有關枚舉器的元數據。 更多...

頭: #include <QMetaEnum>
qmake: QT += core

公共函數

const char * enumName () const
bool isFlag () const
bool isScoped () const
bool isValid () const
const char * key (int index ) const
int keyCount () const
int keyToValue (const char * key , bool * ok = nullptr) const
int keysToValue (const char * keys , bool * ok = nullptr) const
const char * name () const
const char * scope () const
int value (int index ) const
const char * valueToKey (int value ) const
QByteArray valueToKeys (int value ) const

靜態公共成員

QMetaEnum fromType ()

詳細描述

使用 name () for the enumerator's name. The enumerator's keys (names of each enumerated item) are returned by key ();使用 keyCount () 能查找按鍵數。 isFlag () returns whether the enumerator is meant to be used as a flag, meaning that its values can be combined using the OR operator.

The conversion functions keyToValue (), valueToKey (), keysToValue (),和 valueToKeys () allow conversion between the integer representation of an enumeration or set value and its literal representation. The scope () function returns the class scope this enumerator was declared in.

另請參閱 QMetaObject , QMetaMethod ,和 QMetaProperty .

成員函數文檔編製

const char *QMetaEnum:: enumName () const

返迴標誌的枚舉名稱 (在作用域外)。

例如, Qt::AlignmentFlag 標誌擁有 AlignmentFlag 作為枚舉名稱,但 Alignment as as the type name. Non flag enums has the same type and enum names.

枚舉名稱擁有如類型名稱的相同作用域。

該函數在 Qt 5.12 引入。

另請參閱 isValid () 和 name ().

[static] template <typename T> QMetaEnum QMetaEnum:: fromType ()

返迴 QMetaEnum corresponding to the type in the template parameter. The enum needs to be declared with Q_ENUM .

該函數在 Qt 5.5 引入。

bool QMetaEnum:: isFlag () const

返迴 true 若此枚舉器被用作標誌;否則返迴 false。

When used as flags, enumerators can be combined using the OR operator.

另請參閱 keysToValue () 和 valueToKeys ().

bool QMetaEnum:: isScoped () const

返迴 true if this enumerator is declared as a C++11 enum class; otherwise returns false.

該函數在 Qt 5.8 引入。

bool QMetaEnum:: isValid () const

返迴 true if this enum is valid (has a name); otherwise returns false.

另請參閱 name ().

const char *QMetaEnum:: key ( int index ) const

Returns the key with the given index ,或 nullptr if no such key exists.

另請參閱 keyCount (), value (),和 valueToKey ().

int QMetaEnum:: keyCount () const

返迴按鍵數。

另請參閱 key ().

int QMetaEnum:: keyToValue (const char * key , bool * ok = nullptr) const

Returns the integer value of the given enumeration key ,或 -1 若 key 未定義。

key is not defined, * ok is set to false; otherwise * ok 被設為 true。

對於標誌類型,使用 keysToValue ().

另請參閱 valueToKey (), isFlag (),和 keysToValue ().

int QMetaEnum:: keysToValue (const char * keys , bool * ok = nullptr) const

Returns the value derived from combining together the values of the keys using the OR operator, or -1 if keys is not defined. Note that the strings in keys must be '|'-separated.

keys is not defined, * ok is set to false; otherwise * ok 被設為 true。

另請參閱 isFlag (), valueToKey (),和 valueToKeys ().

const char *QMetaEnum:: name () const

Returns the name of the type (without the scope).

例如, Qt::Key 枚舉擁有 Key as the type name and Qt as the scope.

For flags this returns the name of the flag type, not the name of the enum type.

另請參閱 isValid (), scope (),和 enumName ().

const char *QMetaEnum:: scope () const

Returns the scope this enumerator was declared in.

例如, Qt::AlignmentFlag 枚舉擁有 Qt as the scope and AlignmentFlag as the name.

另請參閱 name ().

int QMetaEnum:: value ( int index ) const

Returns the value with the given index ; or returns -1 if there is no such value.

另請參閱 keyCount (), key (),和 keyToValue ().

const char *QMetaEnum:: valueToKey ( int value ) const

Returns the string that is used as the name of the given enumeration value ,或 nullptr if value 未定義。

對於標誌類型,使用 valueToKeys ().

另請參閱 isFlag () 和 valueToKeys ().

QByteArray QMetaEnum:: valueToKeys ( int value ) const

Returns a byte array of '|'-separated keys that represents the given value .

另請參閱 isFlag (), valueToKey (),和 keysToValue ().