#pragma once
#include <QMetaType>
#include <QString>
class test_QMetaType
{
public:
test_QMetaType()
{
}
QString m_body = "AAAAAA";
};
Q_DECLARE_METATYPE(test_QMetaType);
void test_meta_type()
{
qRegisterMetaType<test_QMetaType>();
int id = QMetaType::type("test_QMetaType");
if (id != QMetaType::UnknownType)
{
void *myClassPtr = QMetaType::create(id);
test_QMetaType* a = static_cast<test_QMetaType*>(myClassPtr);
a->m_body = "ABC";
QMetaType::destroy(id, myClassPtr);
myClassPtr = 0;
}
}
本文深入探讨了QMetaType在Qt中的应用,包括如何使用Q_DECLARE_METATYPE宏注册自定义类型,以及如何通过qRegisterMetaType函数进行类型注册。通过实例展示了如何创建和销毁元类型,为Qt开发者提供了实用的代码示例。
2595

被折叠的 条评论
为什么被折叠?



