| Home · All Classes · Modules |
The QMetaType class manages named types in the meta-object system. More...
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().
These are the built-in types supported by QMetaType:
| Constant | Value | Description |
|---|---|---|
| QMetaType.Void | 0 | void |
| QMetaType.Bool | 1 | bool |
| QMetaType.Int | 2 | int |
| QMetaType.UInt | 3 | unsigned int |
| QMetaType.Double | 6 | double |
| QMetaType.QChar | 7 | QChar |
| QMetaType.QString | 10 | QString |
| QMetaType.QByteArray | 12 | QByteArray |
| QMetaType.VoidStar | 128 | void * |
| QMetaType.Long | 129 | long |
| QMetaType.LongLong | 4 | LongLong |
| QMetaType.Short | 130 | short |
| QMetaType.Char | 131 | char |
| QMetaType.ULong | 132 | unsigned long |
| QMetaType.ULongLong | 5 | ULongLong |
| QMetaType.UShort | 133 | unsigned short |
| QMetaType.UChar | 134 | unsigned char |
| QMetaType.Float | 135 | float |
| QMetaType.QObjectStar | 136 | QObject * |
| QMetaType.QWidgetStar | 137 | QWidget * |
| QMetaType.QColorGroup | 63 | QColorGroup |
| QMetaType.QCursor | 74 | QCursor |
| QMetaType.QDate | 14 | QDate |
| QMetaType.QSize | 21 | QSize |
| QMetaType.QTime | 15 | QTime |
| QMetaType.QVariantList | 9 | QVariantList |
| QMetaType.QPolygon | 71 | QPolygon |
| QMetaType.QColor | 67 | QColor |
| QMetaType.QSizeF | 22 | QSizeF |
| QMetaType.QRectF | 20 | QRectF |
| QMetaType.QLine | 23 | QLine |
| QMetaType.QTextLength | 78 | QTextLength |
| QMetaType.QStringList | 11 | QStringList |
| QMetaType.QVariantMap | 8 | QVariantMap |
| QMetaType.QVariantHash | 28 | QVariantHash |
| QMetaType.QIcon | 69 | QIcon |
| QMetaType.QPen | 77 | QPen |
| QMetaType.QLineF | 24 | QLineF |
| QMetaType.QTextFormat | 79 | QTextFormat |
| QMetaType.QRect | 19 | QRect |
| QMetaType.QPoint | 25 | QPoint |
| QMetaType.QUrl | 17 | QUrl |
| QMetaType.QRegExp | 27 | QRegExp |
| QMetaType.QDateTime | 16 | QDateTime |
| QMetaType.QPointF | 26 | QPointF |
| QMetaType.QPalette | 68 | QPalette |
| QMetaType.QFont | 64 | QFont |
| QMetaType.QBrush | 66 | QBrush |
| QMetaType.QRegion | 72 | QRegion |
| QMetaType.QBitArray | 13 | QBitArray |
| QMetaType.QImage | 70 | QImage |
| QMetaType.QKeySequence | 76 | QKeySequence |
| QMetaType.QSizePolicy | 75 | QSizePolicy |
| QMetaType.QPixmap | 65 | QPixmap |
| QMetaType.QLocale | 18 | QLocale |
| QMetaType.QBitmap | 73 | QBitmap |
| QMetaType.QMatrix | 80 | QMatrix |
| QMetaType.QTransform | 81 | QTransform |
| QMetaType.QMatrix4x4 | 82 | QMatrix4x4 |
| QMetaType.QVector2D | 83 | QVector2D |
| QMetaType.QVector3D | 84 | QVector3D |
| QMetaType.QVector4D | 85 | QVector4D |
| QMetaType.QQuaternion | 86 | QQuaternion |
| QMetaType.User | 256 | Base value for user types |
Additional types can be registered using Q_DECLARE_METATYPE().
See also type() and typeName().
Returns true if the datatype with ID type is registered; otherwise returns false.
See also type(), typeName(), and Type.
Returns a handle to the type called typeName, or 0 if there is no such type.
See also isRegistered(), typeName(), and Type.
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.1-snapshot-20100120 for X11 | Copyright © Riverbank Computing Ltd and Nokia 2009 | Qt 4.6.1 |