invalid use of incomplete type 'struct Ui::MainWindow怎么解决?

arabicsara 2010-08-31 04:42:37
mainwindow.cpp: In constructor 'MainWindow::MainWindow(QWidget*)': 
mainwindow.cpp:12: error: invalid use of incomplete type 'struct Ui::MainWindow'
mainwindow.h:10: error: forward declaration of 'struct Ui::MainWindow'
mainwindow.cpp:14: error: invalid use of incomplete type 'struct Ui::MainWindow'
mainwindow.h:10: error: forward declaration of 'struct Ui::MainWindow'
mainwindow.cpp:17: error: invalid use of incomplete type 'struct Ui::MainWindow'
mainwindow.h:10: error: forward declaration of 'struct Ui::MainWindow'
mainwindow.cpp:18: error: invalid use of incomplete type 'struct Ui::MainWindow'
mainwindow.h:10: error: forward declaration of 'struct Ui::MainWindow'
mainwindow.cpp:19: error: invalid use of incomplete type 'struct Ui::MainWindow'
mainwindow.h:10: error: forward declaration of 'struct Ui::MainWindow'
mainwindow.cpp: In destructor 'virtual MainWindow::~MainWindow()':
mainwindow.cpp:33: error: invalid use of incomplete type 'struct Ui::MainWindow'
mainwindow.h:10: error: forward declaration of 'struct Ui::MainWindow'
mainwindow.cpp:34: error: invalid use of incomplete type 'struct Ui::MainWindow'
mainwindow.h:10: error: forward declaration of 'struct Ui::MainWindow'
mainwindow.cpp:35: error: invalid use of incomplete type 'struct Ui::MainWindow'
mainwindow.h:10: error: forward declaration of 'struct Ui::MainWindow'
mainwindow.cpp:39: warning: possible problem detected in invocation of delete operator:
mainwindow.cpp:39: warning: invalid use of incomplete type 'struct Ui::MainWindow'
mainwindow.h:10: warning: forward declaration of 'struct Ui::MainWindow'
mainwindow.cpp:39: note: neither the destructor nor the class-specific operator delete will be called, even if they are declared when the class is defined.
mainwindow.cpp: In member function 'void MainWindow::on_toolButton_browser_clicked()':
mainwindow.cpp:45: error: invalid use of incomplete type 'struct Ui::MainWindow'
mainwindow.h:10: error: forward declaration of 'struct Ui::MainWindow'
mainwindow.cpp:53: error: invalid use of incomplete type 'struct Ui::MainWindow'
mainwindow.h:10: error: forward declaration of 'struct Ui::MainWindow'
mainwindow.cpp:54: error: invalid use of incomplete type 'struct Ui::MainWindow'
mainwindow.h:10: error: forward declaration of 'struct Ui::MainWindow'
mainwindow.cpp: In member function 'int MainWindow::SearchIntofile(const QString&, const QString&, QTreeWidgetItem*)':
mainwindow.cpp:75: warning: unused variable 'i'
mainwindow.cpp: In member function 'int MainWindow::FindFile(const QString&)':
mainwindow.cpp:111: error: invalid use of incomplete type 'struct Ui::MainWindow'
mainwindow.h:10: error: forward declaration of 'struct Ui::MainWindow'
mainwindow.cpp:119: error: invalid use of incomplete type 'struct Ui::MainWindow'
mainwindow.h:10: error: forward declaration of 'struct Ui::MainWindow'
mainwindow.cpp: In member function 'int MainWindow::search()':
mainwindow.cpp:138: error: invalid use of incomplete type 'struct Ui::MainWindow'
mainwindow.h:10: error: forward declaration of 'struct Ui::MainWindow'
mainwindow.cpp:146: error: invalid use of incomplete type 'struct Ui::MainWindow'
mainwindow.h:10: error: forward declaration of 'struct Ui::MainWindow'
mainwindow.cpp: In member function 'int MainWindow::AddFav()':
mainwindow.cpp:179: error: invalid use of incomplete type 'struct Ui::MainWindow'
mainwindow.h:10: error: forward declaration of 'struct Ui::MainWindow'
mainwindow.cpp:180: error: invalid use of incomplete type 'struct Ui::MainWindow'
mainwindow.h:10: error: forward declaration of 'struct Ui::MainWindow'

我修改了代码,修改了资源文件(把一个菜单的ObjectName改了一下),之后就编译出错了
...全文
12872 16 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
keneth2078 2012-09-22
  • 打赏
  • 举报
回复
顶部的objectName 是不容易轻易改变的。得出结论了。
int8 2012-09-07
  • 打赏
  • 举报
回复
也就是说,不能轻易改变顶层部件的objectname?
小小橙123 2012-07-30
  • 打赏
  • 举报
回复
多谢12,13楼,我也碰到同样问题。
love666love 2012-03-28
  • 打赏
  • 举报
回复
我是修改了QObject的objectname出现的错误,解决办法同12楼。
bluesnow208 2012-02-12
  • 打赏
  • 举报
回复
把.ui文件里的objectName修改成其他头文件里引用的名称。
这是你修改ui类带来的错误。
linux_leaner 2011-12-01
  • 打赏
  • 举报
回复
我也碰到了这个问题,不过我把mainwindow.cpp中包含头文件ui_mainwindow.h的语句转移到mainwindow.h中就行了,因为mainwindow.h中有使用到Ui::MainWindow
shixinjing 2011-06-16
  • 打赏
  • 举报
回复
谢谢chenlee的详细解释!
ChenLee_1 2011-05-03
  • 打赏
  • 举报
回复 7
我也碰到了同样的问题,后来发现,用qtDesigner设计的UI主界面,是这样命名的:class Ui_mainWindow
而在ui_mainwindow.h文件的最后,有这么一句话,namespace Ui {
class mainWindow: public Ui_mainWindow {};
} // namespace Ui ,也就是说,Ui_mainwindow被放在了Ui命名空间;
而在QT Creator的mainwindow.h里面,前向申明是这样写的:namespace Ui {
class MainWindow;
}
细心的朋友估计已经发现了,这里应该是class mainWindow,而QT默认的却写成了class MainWindow;换句话说,这是qt的一个bug.
arabicsara 2010-12-17
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 mrdone 的回复:]

熊猫,你没有说明是怎么解决的!
[/Quote]不好意思哈,我是这么解决:每次改完mainwindow的名字id就会出现这种错误,比如mainwindow设置成mainwindow2,而qt代码里没有自动都转成mainwindow2
mrdone 2010-12-17
  • 打赏
  • 举报
回复
熊猫,你没有说明是怎么解决的!
  • 打赏
  • 举报
回复
应该是类没有实体,找不到构造函数。
lefttime 2010-09-01
  • 打赏
  • 举报
回复
光看头文件没什么问题, 只是在类中声明, 将实现引用于源文件而已;
把源文件也贴出来看看, 这样也许更容易定位问题所在```~
arabicsara 2010-09-01
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 lingcheshenyou 的回复:]
头文件中因为Ui::MainWindow类只用了一个指针,所以之前的
namespace Ui{
class MainWindow}
就已经足够了
但是这个提示信息说的是你在MainWindow的构造函数中使用了一个没有实体的类,也就是说你忘记了在mainwindow.cpp中包含 ui_mainwindow.h。如果使用了一个类的实体(与指针相对)但是编译器找不到这个类的实现,那么就会报……
[/Quote].cpp里有ui_mainwindow.h了
千羽鸣 2010-09-01
  • 打赏
  • 举报
回复
头文件中因为Ui::MainWindow类只用了一个指针,所以之前的
namespace Ui{
class MainWindow}
就已经足够了
但是这个提示信息说的是你在MainWindow的构造函数中使用了一个没有实体的类,也就是说你忘记了在mainwindow.cpp中包含 ui_mainwindow.h。如果使用了一个类的实体(与指针相对)但是编译器找不到这个类的实现,那么就会报这个错误。
一定是这样的,对不对?
arabicsara 2010-08-31
  • 打赏
  • 举报
回复
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <qprogressbar.h>
#include <QTreeWidgetItem>
#include "dialog_filter.h"
#include "ui_mainwindow.h"

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public:
int FindFile(const QString & path);
int SearchIntofile(const QString &file_name,const QString &str_find,QTreeWidgetItem* parent=0);
private:
Ui::MainWindow *ui;
Dialog_filter dlg_filter;
// QProgressBar *progressbar;
bool b_SearchFileContnt;//查找文件内容
bool b_CaseSensitive;//大小写敏感
private slots:
void on_pushButton_jump_clicked();
void on_pushButton_filter_clicked();
void on_toolButton_browser_clicked();
int search();
int about();
int AddFav();
void CaseSensitive();
};

#endif // MAINWINDOW_H
原来没有#include "ui_mainwindow.h",加上去也是一样的错误啊
巴依老爷 2010-08-31
  • 打赏
  • 举报
回复
看上去你大概是忘了#include "ui_mainwindow.h"

16,816

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧