QMetaEnum Class
The QMetaEnum class provides meta-data about an enumerator. 更多...
头文件: | #include <QMetaEnum> |
qmake: | QT += core |
公有函数
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 = Q_NULLPTR) const |
int | keysToValue(const char *keys, bool *ok = Q_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() |
详细描述
The QMetaEnum class provides meta-data about an enumerator.
Use name() for the enumerator's name. The enumerator's keys (names of each enumerated item) are returned by key(); use keyCount() to find the number of keys. 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(), and 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, and QMetaProperty.
成员函数
[static]
QMetaEnum QMetaEnum::fromType()
Returns the QMetaEnum corresponding to the type in the template parameter. The enum needs to be declared with Q_ENUM.
This function was introduced in Qt 5.5.
bool QMetaEnum::isFlag() const
Returns true
if this enumerator is used as a flag; otherwise returns false.
When used as flags, enumerators can be combined using the OR operator.
参见 keysToValue() and valueToKeys().
bool QMetaEnum::isScoped() const
Returns true
if this enumerator is declared as a C++11 enum class; otherwise returns false.
This function was introduced in Qt 5.8.
bool QMetaEnum::isValid() const
Returns 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, or 0 if no such key exists.
参见 keyCount(), value(), and valueToKey().
int QMetaEnum::keyCount() const
Returns the number of keys.
参见 key().
int QMetaEnum::keyToValue(const char *key, bool *ok = Q_NULLPTR) const
Returns the integer value of the given enumeration key, or -1 if key is not defined.
If key is not defined, *ok is set to false; otherwise *ok is set to true.
For flag types, use keysToValue().
参见 valueToKey(), isFlag(), and keysToValue().
int QMetaEnum::keysToValue(const char *keys, bool *ok = Q_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.
If keys is not defined, *ok is set to false; otherwise *ok is set to true.
参见 isFlag(), valueToKey(), and valueToKeys().
const char *QMetaEnum::name() const
Returns the name of the enumerator (without the scope).
For example, the Qt::AlignmentFlag enumeration has AlignmentFlag
as the name and Qt as the scope.
const char *QMetaEnum::scope() const
Returns the scope this enumerator was declared in.
For example, the Qt::AlignmentFlag enumeration has 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(), and keyToValue().
const char *QMetaEnum::valueToKey(int value) const
Returns the string that is used as the name of the given enumeration value, or 0 if value is not defined.
For flag types, use valueToKeys().
参见 isFlag() and valueToKeys().
QByteArray QMetaEnum::valueToKeys(int value) const
Returns a byte array of '|'-separated keys that represents the given value.
参见 isFlag(), valueToKey(), and keysToValue().