来自:http://www.cryfeifei.cn/246.html
张小飞 发布了一篇文章
《Qt中报错error: allocation of incomplete type ‘Ui::‘》
3月前 • Qt, Qt技巧 • allocation of incomplete type, Ui:: • 957 • 0
每次在Qt中单独添加UI文件的时候,都会遇到这个问题。需要注意这么几点
切记要与类名保持一致
举个栗子我的类名叫
CMainWidget
那我的文件名就叫
cmainwidget.h
cmainwidget.cpp
那需要在cmainwidget.h头文件中添加
namespace Ui{
class cmainwidget;
}
在cmainwidget.cpp添加
#include "ui_cmainwidget.h"
添加私有成员变量
private:
Ui::cmainwidget* ui;
初始化成员变量
ui(new Ui::cmainwidget)
构造函数中
ui->setupUi(this);