6.0.0-rc4Source

QMetaEnum Class

The QMetaEnum class provides meta-data about an enumerator. More…

Header#include <QMetaEnum>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes

List of all members, including inherited members

Public Functions

QMetaEnum()
const char *name() const
const char *enumName() const
const char *scope() const
boolisFlag() const
boolisScoped() const
intkeyCount() const
const char *key(int i) const
intvalue(int i) const
intkeyToValue(const char *key, bool *ok = nullptr) const
const char *valueToKey(int value) const
intkeysToValue(const char *keys, bool *ok = nullptr) const
boolis64Bit() const
std::optional<quint64>value64(int i) const
std::optional<quint64>keyToValue64(const char *key) const
QByteArrayvalueToKeys(int value) const
const QMetaObject *enclosingMetaObject() const
boolisValid() const

Static Public Members

QMetaEnumfromType()

Detailed Description

Use it to convert between the values of an enumeration declared with Q_ENUM() or Q_FLAG() and their names:

QMetaEnum e = QMetaEnum::fromType<Shape::Kind>();
e.valueToKey(Shape::Circle);   // "Circle"
e.keyToValue("Square");        // Shape::Square

See also QMetaObject::enumerator() and QMetaProperty::enumerator().

Differences from Qt

Values are int, so is64Bit() is always false. There is no QMetaEnum::fromType() for an enumeration that is not declared with Q_ENUM(), Q_FLAG(), Q_ENUM_NS() or Q_FLAG_NS().

Member Function Documentation

QMetaEnum::QMetaEnum()

Constructs an invalid enumerator.

See also isValid().

const QMetaObject * QMetaEnum::enclosingMetaObject() const

Returns the meta-object of the class or namespace that declares the enumeration.

const char * QMetaEnum::enumName() const

Returns the name of the enumeration, without its scope. For a flags type this is the name of the flags type.

See also name().

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

Returns the meta-data of the enumeration T, which must be declared with Q_ENUM() or Q_FLAG() (or the _NS forms). Returns an invalid object otherwise.

bool QMetaEnum::is64Bit() const

Returns false: the enumerations that ntmoc records have int values.

This function was introduced in 6.9.

See also value64().

bool QMetaEnum::isFlag() const

Returns true if the enumeration is a set of flags declared with Q_FLAG().

See also keysToValue().

bool QMetaEnum::isScoped() const

Returns true if the enumeration is an enum class.

bool QMetaEnum::isValid() const

Returns true if this object describes an enumerator; otherwise returns false.

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

Returns the key at i, or nullptr if i is out of range.

See also value() and keyCount().

int QMetaEnum::keyCount() const

Returns the number of keys.

See also key() and value().

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

Returns the combined value of the keys in keys, which are separated by |, such as "Read|Write". Returns -1 and sets ok to false if a key is unknown; otherwise sets ok to true if it is not nullptr.

See also valueToKeys() and keyToValue().

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

Returns the value of the key key, which may be qualified with the scope, such as "Mode::Up" or "Counter::Up". Returns -1 if there is no such key and sets ok to false; otherwise sets ok to true if it is not nullptr.

See also valueToKey() and keysToValue().

std::optional<quint64> QMetaEnum::keyToValue64(const char *key) const

Returns the value of key as a 64-bit number, or std::nullopt if the enumeration has no such key.

This function was introduced in 6.9.

See also keyToValue().

const char * QMetaEnum::name() const

Returns the name of the enumerator, without its scope.

See also enumName() and scope().

const char * QMetaEnum::scope() const

Returns the name of the class or namespace that declares the enumeration.

See also name().

int QMetaEnum::value(int i) const

Returns the value of the key at i, or -1 if i is out of range.

See also key().

std::optional<quint64> QMetaEnum::value64(int i) const

Returns the value of the key at i as a 64-bit number, sign-extended, or std::nullopt if i is out of range.

This function was introduced in 6.9.

See also value() and keyCount().

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

Returns the key of the first enumerator with the value value, or nullptr if there is none.

See also keyToValue() and valueToKeys().

QByteArray QMetaEnum::valueToKeys(int value) const

Returns the keys whose values are set in value, separated by |. A value of 0 gives the key whose value is 0, if there is one. Bits that no key accounts for are ignored.

See also keysToValue() and valueToKey().