Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QMetaEnum Class Reference

\inmodule QtCore More...

#include <qmetaobject.h>

+ Collaboration diagram for QMetaEnum:

Public Member Functions

constexpr QMetaEnum ()
 
const char * name () const
 Returns the name of the type (without the scope).
 
const char * enumName () const
 Returns the enum name of the flag (without the scope).
 
QMetaType metaType () const
 Returns the meta type of the enum.
 
bool isFlag () const
 Returns true if this enumerator is used as a flag; otherwise returns false.
 
bool isScoped () const
 
int keyCount () const
 Returns the number of keys.
 
const char * key (int index) const
 Returns the key with the given index, or \nullptr if no such key exists.
 
int value (int index) const
 Returns the value with the given index; or returns -1 if there is no such value.
 
const char * scope () const
 Returns the scope this enumerator was declared in.
 
int keyToValue (const char *key, bool *ok=nullptr) const
 Returns the integer value of the given enumeration key, or -1 if key is not defined.
 
const char * valueToKey (int value) const
 Returns the string that is used as the name of the given enumeration value, or \nullptr if value is not defined.
 
int 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.
 
QByteArray valueToKeys (int value) const
 Returns a byte array of '|'-separated keys that represents the given value.
 
const QMetaObjectenclosingMetaObject () const
 
bool isValid () const
 Returns true if this enum is valid (has a name); otherwise returns false.
 

Static Public Member Functions

template<typename T >
static QMetaEnum fromType ()
 

Friends

struct QMetaObject
 
struct QMetaObjectPrivate
 

Detailed Description

\inmodule QtCore

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.

See also
QMetaObject, QMetaMethod, QMetaProperty

Definition at line 263 of file qmetaobject.h.

Constructor & Destructor Documentation

◆ QMetaEnum()

QMetaEnum::QMetaEnum ( )
inlineconstexpr

Definition at line 266 of file qmetaobject.h.

Member Function Documentation

◆ enclosingMetaObject()

const QMetaObject * QMetaEnum::enclosingMetaObject ( ) const
inline

Definition at line 286 of file qmetaobject.h.

Referenced by isScopeMatch().

+ Here is the caller graph for this function:

◆ enumName()

const char * QMetaEnum::enumName ( ) const

Returns the enum name of the flag (without the scope).

For example, the Qt::AlignmentFlag flag has AlignmentFlag as the enum name, but Alignment as the type name. Non flag enums has the same type and enum names.

Enum names have the same scope as the type name.

Since
5.12
See also
isValid(), name()

Definition at line 3078 of file qmetaobject.cpp.

References rawStringData().

Referenced by QMetaObjectBuilder::addEnumerator(), isScopeMatch(), qt_QMetaEnum_debugOperator(), and qt_QMetaEnum_flagDebugOperator().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fromType()

template<typename T >
template< typename T > QMetaEnum QMetaEnum::fromType ( )
inlinestatic
Since
5.5

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

Definition at line 291 of file qmetaobject.h.

References metaObject().

+ Here is the call graph for this function:

◆ isFlag()

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.

See also
keysToValue(), valueToKeys()

Definition at line 3161 of file qmetaobject.cpp.

References EnumIsFlag.

Referenced by QMetaObjectBuilder::addEnumerator().

+ Here is the caller graph for this function:

◆ isScoped()

bool QMetaEnum::isScoped ( ) const
Since
5.8

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

Definition at line 3174 of file qmetaobject.cpp.

References EnumIsScoped.

Referenced by QMetaObjectBuilder::addEnumerator(), qt_QMetaEnum_debugOperator(), and qt_QMetaEnum_flagDebugOperator().

+ Here is the caller graph for this function:

◆ isValid()

bool QMetaEnum::isValid ( ) const
inline

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

See also
name()

Definition at line 288 of file qmetaobject.h.

◆ key()

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

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

See also
keyCount(), value(), valueToKey()

Definition at line 3128 of file qmetaobject.cpp.

References QMetaObject::d, and rawStringData().

Referenced by QMetaObjectBuilder::addEnumerator().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ keyCount()

int QMetaEnum::keyCount ( ) const

Returns the number of keys.

See also
key()

Definition at line 3116 of file qmetaobject.cpp.

Referenced by QMetaObjectBuilder::addEnumerator().

+ Here is the caller graph for this function:

◆ 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.

If keys is not defined, *{ok} is set to false; otherwise {ok} is set to true.

See also
isFlag(), valueToKey(), valueToKeys()

Definition at line 3324 of file qmetaobject.cpp.

References QMetaObject::d, i, isScopeMatch(), keys, list, ok, parse_scope(), parseEnumFlags(), and stringDataView().

Referenced by QMetaProperty::write(), and QQmlPropertyPrivate::writeEnumProperty().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ keyToValue()

int QMetaEnum::keyToValue ( const char * key,
bool * ok = 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().

See also
valueToKey(), isFlag(), keysToValue()

Definition at line 3232 of file qmetaobject.cpp.

References QMetaObject::d, i, isScopeMatch(), ok, parse_scope(), and stringDataView().

Referenced by toEnumValue(), toEnumValue(), QMetaProperty::write(), and QQmlPropertyPrivate::writeEnumProperty().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ metaType()

QMetaType QMetaEnum::metaType ( ) const

Returns the meta type of the enum.

If the QMetaObject that this enum is part of was generated with Qt 6.5 or earlier, this will be an invalid meta type.

Note
This is the meta type of the enum itself, not of its underlying integral type. You can retrieve the meta type of the underlying type of the enum using \l{QMetaType::underlyingType()}.
Since
6.6

Definition at line 3097 of file qmetaobject.cpp.

References QMetaObject::d, and priv().

Referenced by QMetaObjectBuilder::addEnumerator(), and QMetaProperty::typeName().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ name()

const char * QMetaEnum::name ( ) const

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

For example, the Qt::Key enumeration has Key as the type name and \l Qt as the scope.

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

See also
isValid(), scope(), enumName()

Definition at line 3059 of file qmetaobject.cpp.

References rawStringData().

Referenced by QMetaObjectBuilder::addEnumerator(), and QQmlMetaType::clone().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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.

See also
name()

Definition at line 3189 of file qmetaobject.cpp.

References QMetaObject::className().

Referenced by qt_QMetaEnum_debugOperator(), and qt_QMetaEnum_flagDebugOperator().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ value()

int QMetaEnum::value ( int index) const

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

See also
keyCount(), key(), keyToValue()

Definition at line 3143 of file qmetaobject.cpp.

References QMetaObject::d.

Referenced by QMetaObjectBuilder::addEnumerator().

+ Here is the caller graph for this function:

◆ valueToKey()

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

Returns the string that is used as the name of the given enumeration value, or \nullptr if value is not defined.

For flag types, use valueToKeys().

See also
isFlag(), valueToKeys()

Definition at line 3259 of file qmetaobject.cpp.

References QMetaObject::d, i, and rawStringData().

Referenced by QQnxButtonEventNotifier::QQnxButtonEventNotifier(), errorToString(), QtDebugUtils::formatQEnum(), QXcbWindow::handleXIMouseEvent(), qt_QMetaEnum_debugOperator(), QTest::Internal::toString(), and QTest::Internal::toString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ valueToKeys()

QByteArray QMetaEnum::valueToKeys ( int value) const

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

See also
isFlag(), valueToKey(), keysToValue()

Definition at line 3386 of file qmetaobject.cpp.

References QMetaObject::d, i, keys, and stringDataView().

Referenced by QtDebugUtils::formatQFlags(), qt_QMetaEnum_flagDebugOperator(), QTest::Internal::toString(), and QTest::Internal::toString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ QMetaObject

friend struct QMetaObject
friend

Definition at line 318 of file qmetaobject.h.

◆ QMetaObjectPrivate

friend struct QMetaObjectPrivate
friend

Definition at line 319 of file qmetaobject.h.


The documentation for this class was generated from the following files: