使用 Qt 5,可以使用如下代码:
// Test.h
#include <QObject>
#include <QMetaObject>
class LanguageModel;
class Test : public QObject
{
Q_OBJECT
Q_PROPERTY(LanguageModel*, ...)
public:
};
// Test.cpp
#include "Test.h"
#include "LanguageModel.h"
// LanguageModel.h
#include <QObject>
#include <QMetaObject>
class LanguageModel : public QObject
{
Q_OBJECT
}
现在我正在尝试将项目转换为 Qt 6,但上面的代码在生成的“debug\moc_Test.cpp”文件中失败,并显示以下错误消息:
C:\Qt\6.1.0\msvc2019_64\include\QtCore\qmetatype.h:778: error: C2338: Type argument of Q_PROPERTY or Q_DECLARE_METATYPE(T*) must be fully defined
用直接头文件替换类前向定义包含工作:
// Test.h
#include <QObject>
#include <QMetaObject>
#include "LanguageModel.h" //class LanguageModel;
class Test : public QObject
{
Q_OBJECT
Q_PROPERTY(LanguageModel*, ...)
public:
};
如何继续使用类定义而不是在 Qt 6 中包含标题?
问候,