Obsolete Members for QMetaType

QMetaType 的以下成员已被弃用。提供这些成员是为了保持旧源代码的正常运行。我们强烈建议不要在新代码中使用它们。

静态公共成员

(deprecated) bool compare(const void *lhs, const void *rhs, int typeId, int *result)
(deprecated) void *construct(int type, void *where, const void *copy)
(deprecated) bool convert(const void *from, int fromTypeId, void *to, int toTypeId)
(deprecated) void *create(int type, const void *copy = nullptr)
(deprecated) bool debugStream(QDebug &dbg, const void *rhs, int typeId)
(deprecated) void destroy(int type, void *data)
(deprecated) void destruct(int type, void *where)
(deprecated) bool hasRegisteredDebugStreamOperator()
(deprecated) bool hasRegisteredDebugStreamOperator(int typeId)
(deprecated) bool load(QDataStream &stream, int type, void *data)
(deprecated) const QMetaObject *metaObjectForType(int type)
(deprecated) bool save(QDataStream &stream, int type, const void *data)
(deprecated) int sizeOf(int type)
(deprecated) int type(const char *typeName)
(deprecated) int type(const QByteArray &typeName)
(deprecated) QMetaType::TypeFlags typeFlags(int type)
(deprecated) const char *typeName(int typeId)

相关非成员

(deprecated) int qRegisterMetaType(const char *typeName)

成员函数文档

[static, deprecated] bool QMetaType::compare(const void *lhs, const void *rhs, int typeId, int *result)

该函数已被弃用。我们强烈建议不要在新代码中使用它。

请使用非静态比较方法

比较lhsrhs 中的对象。两个对象都需要是typeId 类型。如果lhs 小于、等于或大于rhs ,则result 被设置为小于、等于或大于零。如果比较成功,则返回true ,否则返回false

[static, deprecated] void *QMetaType::construct(int type, void *where, const void *copy)

该函数已被弃用。我们强烈建议不要在新代码中使用该函数。

where 编址的现有内存中构造一个type 的值,该值是copy 的副本,并返回where 。如果copy 为零,则默认构造一个值。

这是一个低级函数,用于明确管理用于存储类型的内存。如果不需要这种级别的控制,可以考虑调用create() (也就是说,使用 "new "而不是 "placement new")。

您必须确保where 指向可以存储type 类型值的位置,并且where 已适当对齐。类型的大小可以通过调用sizeOf() 查询。

对齐的经验法则是,除非对齐方式大于平台的最大有效对齐方式,否则类型应按其自然边界对齐,即大于类型的最小 2 的幂次。在实际应用中,只有特殊硬件指令(如 x86 上对齐的 SSE 加载和存储)才需要大于 2 * sizeof(void*) 的对齐方式。

另请参见 destruct() 和sizeOf()。

[static, deprecated] bool QMetaType::convert(const void *from, int fromTypeId, void *to, int toTypeId)

该函数已被弃用。我们强烈建议不要在新代码中使用它。

from 中的对象从fromTypeId 转换到to 类型为toTypeId 的预分配空间。如果转换成功,则返回true ,否则返回 false。

fromto 都必须是有效的指针。

[static, deprecated] void *QMetaType::create(int type, const void *copy = nullptr)

该函数已被弃用。我们强烈建议不要在新代码中使用该函数。

返回copy 的副本,假定其类型为type 。如果copy 为零,则创建一个默认构造实例。

另请参阅 destroy(),isRegistered() 和Type

[static, deprecated] bool QMetaType::debugStream(QDebug &dbg, const void *rhs, int typeId)

该函数已被弃用。我们强烈建议不要在新代码中使用它。

这是一个重载函数。

[static, deprecated] void QMetaType::destroy(int type, void *data)

该函数已被弃用。我们强烈建议不要在新代码中使用该函数。

销毁data ,假定它属于给定的type

另请参阅 create(),isRegistered() 和Type

[static, deprecated] void QMetaType::destruct(int type, void *where)

该函数已被弃用。我们强烈建议不要在新代码中使用该函数。

析构给定type 的值,该值位于where

destroy() 不同,该函数只调用类型的析构函数,而不调用删除操作符。

另请参见 construct()。

[static, deprecated] template <typename T> bool QMetaType::hasRegisteredDebugStreamOperator()

该函数已被弃用。我们强烈建议不要在新代码中使用它。

如果元类型系统为 T 类型注册了调试流操作符,则返回true

[static, deprecated] bool QMetaType::hasRegisteredDebugStreamOperator(int typeId)

该函数已被弃用。我们强烈建议不要在新代码中使用它。

请使用QMetaType::hasRegisteredDebugStreamOperator() 代替。

如果元类型系统为类型 idtypeId 注册了调试流操作符,则返回true

[static, deprecated] bool QMetaType::load(QDataStream &stream, int type, void *data)

该函数已被弃用。我们强烈建议不要在新代码中使用它。

这是一个重载函数。

[static, deprecated] const QMetaObject *QMetaType::metaObjectForType(int type)

该函数已被弃用。我们强烈建议不要在新代码中使用它。

返回QMetaType::metaObject ,用于type

另请参见 metaObject()。

[static, deprecated] bool QMetaType::save(QDataStream &stream, int type, const void *data)

该函数已被弃用。我们强烈建议不要在新代码中使用它。

这是一个重载函数。

[static, deprecated] int QMetaType::sizeOf(int type)

该函数已被弃用。我们强烈建议不要在新代码中使用它。

以字节为单位返回给定type 的大小(即 sizeof(T),其中 T 是type 参数标识的实际类型)。

该函数通常与construct() 一起使用,对类型使用的内存进行底层管理。

另请参见 construct() 和QMetaType::alignOf()。

[static, deprecated] int QMetaType::type(const char *typeName)

该函数已被弃用。我们强烈建议不要在新代码中使用它。

返回名为typeName 的类型的句柄,如果没有该类型,则返回QMetaType::UnknownType

另请参阅 isRegistered(),typeName() 和Type

[static, deprecated] int QMetaType::type(const QByteArray &typeName)

该函数已被弃用。我们强烈建议不要在新代码中使用它。

这是一个重载函数。

返回typeName 类型的句柄,如果没有该类型,则返回 0。

另请参阅 isRegistered() 和typeName()。

[static, deprecated] QMetaType::TypeFlags QMetaType::typeFlags(int type)

该函数已被弃用。我们强烈建议不要在新代码中使用它。

返回给定type 的标志。

另请参见 QMetaType::TypeFlags

[static, deprecated] const char *QMetaType::typeName(int typeId)

该函数已被弃用。我们强烈建议不要在新代码中使用它。

返回与给定typeId 相关联的类型名称,如果没有找到匹配的类型,则返回一个空指针。返回的指针不得删除。

另请参阅 type()、isRegistered()、Typename()。

相关非成员

[deprecated] template <typename T> int qRegisterMetaType(const char *typeName)

该函数已被弃用。我们强烈建议不要在新代码中使用它。

T 注册类型名typeName 。返回QMetaType 使用的内部 ID。任何具有公共默认构造函数、公共复制构造函数和公共析构函数的类或结构体都可以注册。

该函数要求T 在调用该函数时是完全定义的类型。对于指针类型,它还要求所指向的类型是完全定义的。使用Q_DECLARE_OPAQUE_POINTER() 可以注册指向前向声明类型的指针。

注册类型后,就可以在运行时动态创建和销毁该类型的对象。

本示例注册了类MyClass

qRegisterMetaType<MyClass>("MyClass");

该函数可用于注册类型定义,以便QMetaProperty 或在 QueuedConnections 中使用。

类型定义QString自定义字符串;qRegisterMetaType<CustomString>("CustomString");

警告: 该函数仅在注册别名(类型定义)时有用,其他情况下应使用Q_DECLARE_METATYPEqMetaTypeId() 代替。

另请参阅 isRegistered() 和Q_DECLARE_METATYPE()。

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.