QMetaType¶

PyQt5.QtCore.QMetaType

Description¶

The QMetaType class manages named types in the meta-object system.

The class is used as a helper to marshall types in QVariant and in queued signals and slots connections. It associates a type name to a type so that it can be created and destructed dynamically at run-time. Declare new types with Q_DECLARE_METATYPE() to make them available to QVariant and other template-based functions. Call qRegisterMetaType() to make types available to non-template based functions, such as the queued signal and slot connections.

Any class or struct that has a public default constructor, a public copy constructor, and a public destructor can be registered.

The following code allocates and destructs an instance of MyClass:

# int id = QMetaType::type("MyClass");
# if (id != QMetaType::UnknownType) {
#     void *myClassPtr = QMetaType::create(id);
#     ...
#     QMetaType::destroy(id, myClassPtr);
#     myClassPtr = 0;
# }

If we want the stream operators operator<<() and operator>>() to work on QVariant objects that store custom types, the custom type must provide operator<<() and operator>>() operators.

See also

Q_DECLARE_METATYPE(), QVariant::setValue(), value(), QVariant::fromValue().

Classes¶

TypeFlags

Enums¶

Type

These are the built-in types supported by QMetaType:

Additional types can be registered using Q_DECLARE_METATYPE().

See also

type(), typeName().

Member

Value

Description

Bool

1

bool

Char

131

char

Double

6

double

FirstGuiType

TODO

TODO

Float

135

float

Int

2

int

LastCoreType

TODO

TODO

Long

129

long

LongLong

4

QBitArray

13

QBitmap

73

QBrush

66

QByteArray

12

QByteArrayList

TODO

QByteArrayList

QCborArray

TODO

TODO

QCborMap

TODO

TODO

QCborSimpleType

TODO

TODO

QCborValue

TODO

TODO

QChar

7

QColor

67

QCursor

74

QDate

14

QDateTime

16

QEasingCurve

29

QFont

64

QIcon

69

QImage

70

QJsonArray

TODO

QJsonArray

QJsonDocument

TODO

QJsonDocument

QJsonObject

TODO

QJsonObject

QJsonValue

TODO

QJsonValue

QKeySequence

76

QLine

23

QLineF

24

QLocale

18

QMatrix

80

QMatrix4x4

82

QModelIndex

TODO

QModelIndex

QObjectStar

136

QObject *

QPalette

68

QPen

77

QPersistentModelIndex

TODO

QPersistentModelIndex (since 5.5)

QPixmap

65

QPoint

25

QPointF

26

QPolygon

71

QPolygonF

TODO

QPolygonF

QQuaternion

86

QRect

19

QRectF

20

QRegExp

27

QRegion

72

QRegularExpression

TODO

QRegularExpression

QSize

21

QSizeF

22

QSizePolicy

75

QString

10

QStringList

11

QTextFormat

79

QTextLength

78

QTime

15

QTransform

81

QUrl

17

QUuid

TODO

QUuid

QVariant

138

QVariantHash

28

QVariantList

9

QVariantMap

8

QVector2D

83

QVector3D

84

QVector4D

85

SChar

TODO

signed char

Short

130

short

UChar

134

unsigned char

UInt

3

unsigned int

ULong

132

unsigned long

ULongLong

5

UnknownType

TODO

This is an invalid type id. It is returned from QMetaType for types that are not registered

User

256

Base value for user types

UShort

133

unsigned short

Void

0

void

VoidStar

128

void \*


TypeFlag

TODO

Member

Value

Description

IsEnumeration

TODO

TODO

MovableType

TODO

TODO

NeedsConstruction

TODO

TODO

NeedsDestruction

TODO

TODO

PointerToQObject

TODO

TODO

Methods¶

__init__(int)

TODO


flags() → TypeFlags

TODO


id() → int

TODO


isRegistered() → bool

TODO


@staticmethod
isRegistered(int) → bool

Returns true if the datatype with ID type is registered; otherwise returns false.

See also

type(), typeName(), Type.


isValid() → bool

TODO


@staticmethod
metaObjectForType(int) → QMetaObject

TODO


@staticmethod
type(str) → int

Returns a handle to the type called typeName, or QMetaType::UnknownType if there is no such type.

See also

isRegistered(), typeName(), Type.


@staticmethod
typeFlags(int) → TypeFlags

TODO


@staticmethod
typeName(int) → str

Returns the type name associated with the given typeId, or a null pointer if no matching type was found. The returned pointer must not be deleted.

See also

type(), isRegistered(), Type.