【发布时间】:2020-08-27 15:53:43
【问题描述】:
我正在尝试在 Ui 命名空间内的 Qt 中创建一个类。 在我的命名空间中,我已经有 2 个使用 Qt Designer 制作的类,使用它作为参考并不能帮助我解决问题。
在myclass.h我放
namespace Ui {class MyClass};
class MyClass : public QObject
{Q_OBJECT
private:
Ui::MyClass* ui;
//body
}
我把myclass.cpp放进去
MyClass::MyClass(QObject *parent) :QObject(parent),ui (new Ui::MyClass)
//Here I have : allocation of incomplete type 'Ui::MyClass'
{
ui->setupUi(this);
//Here I have : member access into incomplete type Ui::MyClass'
}
我看到了way of defining class in a namespace,但我没有找到解决我的错误的方法。
【问题讨论】:
-
namespace Ui {class MyClass}不会编译。即使您添加缺少的;以使该行有效,这仍然只是一个前向声明。您的类既没有在该命名空间中声明也没有定义。
标签: c++ namespaces