QMetaType

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

Inheritance diagram of PySide6.QtCore.QMetaType

Synopsis

Functions

Static functions

Detailed Description

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:

id = QMetaType.type("MyClass")
if id != QMetaType.UnknownType:
    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() setValue() value() fromValue()

class PySide6.QtCore.QMetaType

PySide6.QtCore.QMetaType(type)

Parameters

type – int

Constructs a QMetaType object that contains all information about type typeId.

PySide6.QtCore.QMetaType.Type

These are the built-in types supported by QMetaType :

Constant

Description

QMetaType.Void

void

QMetaType.Bool

bool

QMetaType.Int

int

QMetaType.UInt

unsigned int

QMetaType.Double

double

QMetaType.QChar

QMetaType.QString

QMetaType.QByteArray

QMetaType.Nullptr

std::nullptr_t

QMetaType.VoidStar

void *

QMetaType.Long

long

QMetaType.LongLong

QMetaType.Short

short

QMetaType.Char

char

QMetaType.Char16

char16_t

QMetaType.Char32

char32_t

QMetaType.ULong

unsigned long

QMetaType.ULongLong

QMetaType.UShort

unsigned short

QMetaType.SChar

signed char

QMetaType.UChar

unsigned char

QMetaType.Float

float

QMetaType.QObjectStar

QObject *

QMetaType.QVariant

QMetaType.QCursor

QMetaType.QDate

QMetaType.QSize

QMetaType.QTime

QMetaType.QVariantList

QMetaType.QPolygon

QMetaType.QPolygonF

QMetaType.QColor

QMetaType.QColorSpace

(introduced in Qt 5.15)

QMetaType.QSizeF

QMetaType.QRectF

QMetaType.QLine

QMetaType.QTextLength

QMetaType.QStringList

QMetaType.QVariantMap

QMetaType.QVariantHash

QMetaType.QIcon

QMetaType.QPen

QMetaType.QLineF

QMetaType.QTextFormat

QMetaType.QRect

QMetaType.QPoint

QMetaType.QUrl

QMetaType.QRegularExpression

QMetaType.QDateTime

QMetaType.QPointF

QMetaType.QPalette

QMetaType.QFont

QMetaType.QBrush

QMetaType.QRegion

QMetaType.QBitArray

QMetaType.QImage

QMetaType.QKeySequence

QMetaType.QSizePolicy

QMetaType.QPixmap

QMetaType.QLocale

QMetaType.QBitmap

QMetaType.QTransform

QMetaType.QMatrix4x4

QMetaType.QVector2D

QMetaType.QVector3D

QMetaType.QVector4D

QMetaType.QQuaternion

QMetaType.QEasingCurve

QMetaType.QJsonValue

QMetaType.QJsonObject

QMetaType.QJsonArray

QMetaType.QJsonDocument

QMetaType.QCborValue

QMetaType.QCborArray

QMetaType.QCborMap

QMetaType.QCborSimpleType

QMetaType.QModelIndex

QMetaType.QPersistentModelIndex

(introduced in Qt 5.5)

QMetaType.QUuid

QMetaType.QByteArrayList

QMetaType.User

Base value for user types

QMetaType.UnknownType

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

Additional types can be registered using Q_DECLARE_METATYPE() .

See also

type() typeName()

PySide6.QtCore.QMetaType.TypeFlag

The enum describes attributes of a type supported by QMetaType .

Constant

Description

QMetaType.NeedsConstruction

This type has non-trivial constructors. If the flag is not set instances can be safely initialized with memset to 0.

QMetaType.NeedsDestruction

This type has a non-trivial destructor. If the flag is not set calls to the destructor are not necessary before discarding objects.

QMetaType.RelocatableType

An instance of a type having this attribute can be safely moved to a different memory location using memcpy.

QMetaType.IsEnumeration

This type is an enumeration.

QMetaType.IsUnsignedEnumeration

If the type is an Enumeration, its underlying type is unsigned.

QMetaType.PointerToQObject

This type is a pointer to a derived of QObject .

QMetaType.IsPointer

This type is a pointer to another type.

PySide6.QtCore.QMetaType.alignOf()
Return type

qsizetype

Returns the alignment of the type in bytes (i.e. alignof(T), where T is the actual type for which this QMetaType instance was constructed for).

This function is typically used together with to perform low-level management of the memory used by a type.

static PySide6.QtCore.QMetaType.canConvert(fromType, toType)
Parameters
Return type

bool

Returns true if convert can convert from fromType to toType.

The following conversions are supported by Qt:

Type

Automatically Cast To

Bool

QChar , Double , Int , LongLong , QString , UInt , ULongLong

QByteArray

Double , Int , LongLong , QString , UInt , ULongLong , QUuid

QChar

Bool , Int , UInt , LongLong , ULongLong

QColor

QString

QDate

QDateTime , QString

QDateTime

QDate , QString , QTime

Double

Bool , Int , LongLong , QString , UInt , ULongLong

QFont

QString

Int

Bool , QChar , Double , LongLong , QString , UInt , ULongLong

QKeySequence

Int , QString

QVariantList

QStringList (if the list’s items can be converted to QStrings)

LongLong

Bool , QByteArray , QChar , Double , Int , QString , UInt , ULongLong

QPoint

QPointF

QRect

QRectF

QString

Bool , QByteArray , QChar , QColor , QDate , QDateTime , Double , QFont , Int , QKeySequence , LongLong , QStringList , QTime , UInt , ULongLong , QUuid

QStringList

QVariantList , QString (if the list contains exactly one item)

QTime

QString

UInt

Bool , QChar , Double , Int , LongLong , QString , ULongLong

ULongLong

Bool , QChar , Double , Int , LongLong , QString , UInt

QUuid

QByteArray , QString

Casting between primitive type (int, float, bool etc.) is supported.

Converting between pointers of types derived from QObject will also return true for this function if a qobject_cast from the type described by fromType to the type described by toType would succeed.

A cast from a sequential container will also return true for this function if the toType is QVariantList .

Similarly, a cast from an associative container will also return true for this function the toType is QVariantHash or QVariantMap .

See also

convert() QSequentialIterable Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE() QAssociativeIterable Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE()

static PySide6.QtCore.QMetaType.canView(fromType, toType)
Parameters
Return type

bool

Returns true if view can create a mutable view of type toType on type fromType.

Converting between pointers of types derived from QObject will return true for this function if a qobject_cast from the type described by fromType to the type described by toType would succeed.

You can create a mutable view of type QSequentialIterable on any container registered with Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE() .

Similarly you can create a mutable view of type QAssociativeIterable on any container registered with Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE() .

See also

convert() QSequentialIterable Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE() QAssociativeIterable Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE()

static PySide6.QtCore.QMetaType.compare(lhs, rhs, typeId, result)
Parameters
  • lhsvoid

  • rhsvoid

  • typeId – int

  • result – int

Return type

bool

Note

This function is deprecated.

Use the non-static compare method instead

Compares the objects at lhs and rhs. Both objects need to be of type typeId. result is set to less than, equal to or greater than zero, if lhs is less than, equal to or greater than rhs. Returns true, if the comparison succeeded, otherwise false.

static PySide6.QtCore.QMetaType.construct(type, where, copy)
Parameters
  • type – int

  • wherevoid

  • copyvoid

Return type

void

Note

This function is deprecated.

Constructs a value of the given type in the existing memory addressed by where, that is a copy of copy, and returns where. If copy is zero, the value is default constructed.

This is a low-level function for explicitly managing the memory used to store the type. Consider calling create() if you don’t need this level of control (that is, use “new” rather than “placement new”).

You must ensure that where points to a location that can store a value of type type, and that where is suitably aligned. The type’s size can be queried by calling sizeOf() .

The rule of thumb for alignment is that a type is aligned to its natural boundary, which is the smallest power of 2 that is bigger than the type, unless that alignment is larger than the maximum useful alignment for the platform. For practical purposes, alignment larger than 2 * sizeof(void*) is only necessary for special hardware instructions (e.g., aligned SSE loads and stores on x86).

See also

destruct() sizeOf()

PySide6.QtCore.QMetaType.construct(where[, copy=None])
Parameters
  • wherevoid

  • copyvoid

Return type

void

Constructs a value of the type that this QMetaType instance was constructed for in the existing memory addressed by where, that is a copy of copy, and returns where. If copy is zero, the value is default constructed.

This is a low-level function for explicitly managing the memory used to store the type. Consider calling if you don’t need this level of control (that is, use “new” rather than “placement new”).

You must ensure that where points to a location where the new value can be stored and that where is suitably aligned. The type’s size can be queried by calling sizeOf() .

The rule of thumb for alignment is that a type is aligned to its natural boundary, which is the smallest power of 2 that is bigger than the type, unless that alignment is larger than the maximum useful alignment for the platform. For practical purposes, alignment larger than 2 * sizeof(void*) is only necessary for special hardware instructions (e.g., aligned SSE loads and stores on x86).

static PySide6.QtCore.QMetaType.convert(fromType, from, toType, to)
Parameters
Return type

bool

Converts the object at from from fromType to the preallocated space at to typed toType. Returns true, if the conversion succeeded, otherwise false.

Both from and to have to be valid pointers.

static PySide6.QtCore.QMetaType.convert(from, fromTypeId, to, toTypeId)
Parameters
  • fromvoid

  • fromTypeId – int

  • tovoid

  • toTypeId – int

Return type

bool

Note

This function is deprecated.

Converts the object at from from fromTypeId to the preallocated space at to typed toTypeId. Returns true, if the conversion succeeded, otherwise false.

Both from and to have to be valid pointers.

PySide6.QtCore.QMetaType.create([copy=None])
Parameters

copyvoid

Return type

void

Returns a copy of copy, assuming it is of the type that this QMetaType instance was created for. If copy is None, creates a default constructed instance.

See also

destroy()

static PySide6.QtCore.QMetaType.create(type[, copy=None])
Parameters
  • type – int

  • copyvoid

Return type

void

Note

This function is deprecated.

Returns a copy of copy, assuming it is of type type. If copy is zero, creates a default constructed instance.

See also

destroy() isRegistered() Type

PySide6.QtCore.QMetaType.destroy(data)
Parameters

datavoid

Destroys the data, assuming it is of the type that this QMetaType instance was created for.

See also

create()

static PySide6.QtCore.QMetaType.destroy(type, data)
Parameters
  • type – int

  • datavoid

Note

This function is deprecated.

Destroys the data, assuming it is of the type given.

See also

create() isRegistered() Type

static PySide6.QtCore.QMetaType.destruct(type, where)
Parameters
  • type – int

  • wherevoid

Note

This function is deprecated.

Destructs the value of the given type, located at where.

Unlike destroy() , this function only invokes the type’s destructor, it doesn’t invoke the delete operator.

See also

construct()

PySide6.QtCore.QMetaType.destruct(data)
Parameters

datavoid

Destructs the value, located at data, assuming that it is of the type for which this QMetaType instance was constructed for.

Unlike , this function only invokes the type’s destructor, it doesn’t invoke the delete operator.

See also

construct()

PySide6.QtCore.QMetaType.equals(lhs, rhs)
Parameters
  • lhsvoid

  • rhsvoid

Return type

bool

Compares the objects at lhs and rhs for equality.

Both objects must be of the type described by this metatype. Can only compare the two objects if a less than or equality operator for the type was visible to the metatype declaration. Otherwise, the metatype never considers values equal. When an equality operator was visible to the metatype declaration, it is authoritative; otherwise, if less than is visible, when neither value is less than the other, the two are considered equal. If values are unordered (see compare() for details) they are not equal.

Returns true if the two objects compare equal, otherwise false.

static PySide6.QtCore.QMetaType.equals(lhs, rhs, typeId, result)
Parameters
  • lhsvoid

  • rhsvoid

  • typeId – int

  • result – int

Return type

bool

Note

This function is deprecated.

PySide6.QtCore.QMetaType.flags()
Return type

TypeFlags

Returns flags of the type for which this QMetaType instance was constructed.

See also

TypeFlags flags()

static PySide6.QtCore.QMetaType.fromName(name)
Parameters

nameQByteArrayView

Return type

PySide6.QtCore.QMetaType

Returns a QMetaType matching typeName. The returned object is not valid if the is not known to QMetaType

static PySide6.QtCore.QMetaType.hasRegisteredConverterFunction(fromType, toType)
Parameters
Return type

bool

Returns true, if the meta type system has a registered conversion from meta type id fromType to toType

PySide6.QtCore.QMetaType.hasRegisteredDataStreamOperators()
Return type

bool

Returns true, if the meta type system has registered data stream operators for this meta type.

PySide6.QtCore.QMetaType.hasRegisteredDebugStreamOperator()
Return type

bool

Returns true, if the meta type system has a registered debug stream operator for this meta type.

static PySide6.QtCore.QMetaType.hasRegisteredDebugStreamOperator(typeId)
Parameters

typeId – int

Return type

bool

Note

This function is deprecated.

Use hasRegisteredDebugStreamOperator() instead.

Returns true, if the meta type system has a registered debug stream operator for type id typeId.

static PySide6.QtCore.QMetaType.hasRegisteredMutableViewFunction(fromType, toType)
Parameters
Return type

bool

Returns true, if the meta type system has a registered mutable view on meta type id fromType of meta type id toType.

PySide6.QtCore.QMetaType.id()
Return type

int

Returns id type hold by this QMetatype instance.

PySide6.QtCore.QMetaType.isEqualityComparable()
Return type

bool

Returns true if a less than or equality operator for the type described by this metatype was visible to the metatype declaration, otherwise false.

PySide6.QtCore.QMetaType.isOrdered()
Return type

bool

Returns true if a less than operator for the type described by this metatype was visible to the metatype declaration, otherwise false.

PySide6.QtCore.QMetaType.isRegistered()
Return type

bool

Returns true if this QMetaType object contains valid information about a type, false otherwise.

static PySide6.QtCore.QMetaType.isRegistered(type)
Parameters

type – int

Return type

bool

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

See also

type() typeName() Type

PySide6.QtCore.QMetaType.isValid()
Return type

bool

Returns true if this QMetaType object contains valid information about a type, false otherwise.

static PySide6.QtCore.QMetaType.load(stream, type, data)
Parameters
Return type

bool

Note

This function is deprecated.

This is an overloaded function.

PySide6.QtCore.QMetaType.load(stream, data)
Parameters
Return type

bool

Reads the object of this type from the given stream into data. Returns true if the object is loaded successfully; otherwise returns false.

The type must have been registered with Q_DECLARE_METATYPE() beforehand.

Normally, you should not need to call this function directly. Instead, use QVariant ‘s operator>>(), which relies on to stream custom types.

See also

save()

static PySide6.QtCore.QMetaType.metaObjectForType(type)
Parameters

type – int

Return type

PySide6.QtCore.QMetaObject

Note

This function is deprecated.

returns metaObject for type

See also

metaObject()

PySide6.QtCore.QMetaType.name()
Return type

str

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

See also

typeName()

PySide6.QtCore.QMetaType.__ne__(b)
Parameters

bPySide6.QtCore.QMetaType

Return type

bool

PySide6.QtCore.QMetaType.__eq__(b)
Parameters

bPySide6.QtCore.QMetaType

Return type

bool

PySide6.QtCore.QMetaType.save(stream, data)
Parameters
Return type

bool

Writes the object pointed to by data to the given stream. Returns true if the object is saved successfully; otherwise returns false.

The type must have been registered with Q_DECLARE_METATYPE() beforehand.

Normally, you should not need to call this function directly. Instead, use QVariant ‘s operator<<(), which relies on to stream custom types.

See also

load()

static PySide6.QtCore.QMetaType.save(stream, type, data)
Parameters
Return type

bool

Note

This function is deprecated.

This is an overloaded function.

PySide6.QtCore.QMetaType.sizeOf()
Return type

qsizetype

Returns the size of the type in bytes (i.e. sizeof(T), where T is the actual type for which this QMetaType instance was constructed for).

This function is typically used together with to perform low-level management of the memory used by a type.

static PySide6.QtCore.QMetaType.sizeOf(type)
Parameters

type – int

Return type

int

Note

This function is deprecated.

Returns the size of the given type in bytes (i.e. sizeof(T), where T is the actual type identified by the type argument).

This function is typically used together with construct() to perform low-level management of the memory used by a type.

static PySide6.QtCore.QMetaType.type(typeName)
Parameters

typeName – str

Return type

int

Note

This function is deprecated.

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

See also

isRegistered() typeName() Type

static PySide6.QtCore.QMetaType.typeFlags(type)
Parameters

type – int

Return type

TypeFlags

Note

This function is deprecated.

Returns flags of the given type.

See also

TypeFlags

static PySide6.QtCore.QMetaType.typeName(type)
Parameters

type – int

Return type

str

Note

This function is deprecated.

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 name()

static PySide6.QtCore.QMetaType.unregisterConverterFunction(from, to)
Parameters
static PySide6.QtCore.QMetaType.unregisterMetaType(type)
Parameters

typePySide6.QtCore.QMetaType

static PySide6.QtCore.QMetaType.unregisterMutableViewFunction(from, to)
Parameters
static PySide6.QtCore.QMetaType.view(fromType, from, toType, to)
Parameters
Return type

bool

Creates a mutable view on the object at from of fromType in the preallocated space at to typed toType. Returns true if the conversion succeeded, otherwise false.