🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# QMetaType Class Reference ## [[QtCore](index.htm) module] 该QMetaType类管理的元对象系统中命名类型。[More...](#details) ### Types * `enum Type { Void, Bool, Int, UInt, ..., User }` ### Methods * `__init__ (self)` * `__init__ (self, QMetaType)` ### Static Methods * `bool isRegistered (int type)` * `int type (str typeName)` * `str typeName (int type)` * * * ## Detailed Description 该QMetaType类管理的元对象系统中命名类型。 这个类被用作辅助马歇尔类型[QVariant](qmetatype.html#Type-enum)而在排队的信号和槽的连接。它关联一个类型名的类型,以便它可以被创建并在运行时动态地破坏。声明新类型的[Q_DECLARE_METATYPE](qmetatype.html#Q_DECLARE_METATYPE)( ) ,使他们能够提供[QVariant](qmetatype.html#Type-enum)与其他基于模板的功能。通话[qRegisterMetaType](qmetatype.html#qRegisterMetaType)()以提供给非基于模板的功能,诸如排队的信号和槽的连接类型。 任何类或结构有一个公共的默认构造函数,公共拷贝构造函数和析构函数市民可以注册。 下面的代码分配和解构的一个实例`MyClass`: ``` int id = QMetaType.type("MyClass"); if (id != 0) { void *myClassPtr = QMetaType.construct(id); ... QMetaType.destroy(id, myClassPtr); myClassPtr = 0; } ``` 如果我们想在流运算符`operator<<()`和`operator>>()`工作在[QVariant](qmetatype.html#Type-enum)存储自定义类型的对象,自定义类型必须提供`operator<<()`和`operator>>()`运营商。 * * * ## Type Documentation ``` QMetaType.Type ``` 这些是由所支持的内置类型[QMetaType](qmetatype.html): | 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](qobject.html)* | | `QMetaType.QWidgetStar` | `137` | [QWidget](qwidget.html)* | | `QMetaType.QVariant` | `138` | 的QVariant | | `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.QEasingCurve` | `29` | QEasingCurve | | `QMetaType.User` | `256` | 用户类型基值 | 其他类型的可使用注册[Q_DECLARE_METATYPE](qmetatype.html#Q_DECLARE_METATYPE)( ) 。 **See also** [type](qmetatype.html#type)()和[typeName](qmetatype.html#typeName)( ) 。 * * * ## Method Documentation ``` QMetaType.__init__ (self) ``` ``` QMetaType.__init__ (self, QMetaType) ``` ``` bool QMetaType.isRegistered (int type) ``` 返回True如果一个ID的数据类型_type_注册,否则返回False 。 **See also** [type](qmetatype.html#type)( )[typeName](qmetatype.html#typeName)()和[Type](qmetatype.html#Type-enum)。 ``` int QMetaType.type (str typeName) ``` 返回的句柄调用类型_typeName_或0,如果不存在这样的类型。 **See also** [isRegistered](qmetatype.html#isRegistered)( )[typeName](qmetatype.html#typeName)()和[Type](qmetatype.html#Type-enum)。 ``` str QMetaType.typeName (int type) ``` 返回与给定关联的类型名称_type_,或者0 ,如果没有匹配的类型被发现。返回的指针不能被删除。 **See also** [type](qmetatype.html#type)( )[isRegistered](qmetatype.html#isRegistered)()和[Type](qmetatype.html#Type-enum)。