Home · All Classes · Modules

QMetaType Class Reference
[QtCore module]

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

Types

Methods

Static Methods


Detailed 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 type 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 == 0) {
     void *myClassPtr = QMetaType.construct(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(), QVariant.value(), and QVariant.fromValue().


Type Documentation

QMetaType.Type

These are the built-in types supported by QMetaType:

ConstantValueDescription
QMetaType.Void0void
QMetaType.Bool1bool
QMetaType.Int2int
QMetaType.UInt3unsigned int
QMetaType.Double6double
QMetaType.QChar7QChar
QMetaType.QString10QString
QMetaType.QByteArray12QByteArray
QMetaType.VoidStar128void *
QMetaType.Long129long
QMetaType.LongLong4LongLong
QMetaType.Short130short
QMetaType.Char131char
QMetaType.ULong132unsigned long
QMetaType.ULongLong5ULongLong
QMetaType.UShort133unsigned short
QMetaType.UChar134unsigned char
QMetaType.Float135float
QMetaType.QObjectStar136QObject *
QMetaType.QWidgetStar137QWidget *
QMetaType.QColorGroup63QColorGroup
QMetaType.QCursor74QCursor
QMetaType.QDate14QDate
QMetaType.QSize21QSize
QMetaType.QTime15QTime
QMetaType.QVariantList9QVariantList
QMetaType.QPolygon71QPolygon
QMetaType.QColor67QColor
QMetaType.QSizeF22QSizeF
QMetaType.QRectF20QRectF
QMetaType.QLine23QLine
QMetaType.QTextLength78QTextLength
QMetaType.QStringList11QStringList
QMetaType.QVariantMap8QVariantMap
QMetaType.QVariantHash28QVariantHash
QMetaType.QIcon69QIcon
QMetaType.QPen77QPen
QMetaType.QLineF24QLineF
QMetaType.QTextFormat79QTextFormat
QMetaType.QRect19QRect
QMetaType.QPoint25QPoint
QMetaType.QUrl17QUrl
QMetaType.QRegExp27QRegExp
QMetaType.QDateTime16QDateTime
QMetaType.QPointF26QPointF
QMetaType.QPalette68QPalette
QMetaType.QFont64QFont
QMetaType.QBrush66QBrush
QMetaType.QRegion72QRegion
QMetaType.QBitArray13QBitArray
QMetaType.QImage70QImage
QMetaType.QKeySequence76QKeySequence
QMetaType.QSizePolicy75QSizePolicy
QMetaType.QPixmap65QPixmap
QMetaType.QLocale18QLocale
QMetaType.QBitmap73QBitmap
QMetaType.QMatrix80QMatrix
QMetaType.QTransform81QTransform
QMetaType.QMatrix4x482QMatrix4x4
QMetaType.QVector2D83QVector2D
QMetaType.QVector3D84QVector3D
QMetaType.QVector4D85QVector4D
QMetaType.QQuaternion86QQuaternion
QMetaType.User256Base value for user types

Additional types can be registered using Q_DECLARE_METATYPE().

See also type() and typeName().


Method Documentation

QMetaType.__init__ (self)

QMetaType.__init__ (self, QMetaType)

bool QMetaType.isRegistered (int)

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

See also type(), typeName(), and Type.

int QMetaType.type (str)

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

See also isRegistered(), typeName(), and Type.

str QMetaType.typeName (int)

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

See also type(), isRegistered(), and Type.


PyQt 4.7.3 for X11Copyright © Riverbank Computing Ltd and Nokia 2010Qt 4.6.2