invalid use of incomplete struct "Ui::Widget" 解决方法
来源:互联网 发布:淘宝卖家账号怎么注册 编辑:程序博客网 时间:2024/06/05 11:11
好久没搞Qt,今天遇到了点小问题,几步搞定,现在记忆不是很好,在这里记下来,作为以后查阅资料。
我在修改UI界面的名字,在build程序的时候,总是有这样的错误:
出错的最大可能:ui文件中并没有提及Widget这个类名!
解决方法:在ui中将这个ui里widget或者dialog或者mainwindow的名字修改为错误里提及的“struct Ui::Widget”中的Widget。总之,要保持ui文件中class项的值与ui中widget或dialog或mainwindow的ObjectName相同!
以下是涉及的各个文件:
1. gui.pro
#-------------------------------------------------
#
# Project created by QtCreator 2011-08-08T17:15:24
#
#-------------------------------------------------
QT += core gui
TARGET = gui
TEMPLATE = app
SOURCES += main.cpp\
widget.cpp
HEADERS += widget.h
FORMS += widget.ui
2. widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
private:
Ui::Widget *ui;
};
#endif // WIDGET_H
3. widget.cpp
#include "ui_widget.h"
#include "widget.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
}
Widget::~Widget()
{
delete ui;
}
4. main.cpp
#include <QtGui/QApplication>
#include "widget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
我找了很久,都不知道问题在哪儿。曾尝试着把Ui namespace去掉,但重新查阅了C++中namespace的用途,发现跟这个invalid use的错误并无关系。曾有网上的帖子说是一个Qt的bug,应该将Widget类名的W变为小写,这个方法依然失效。经历了好多次的折腾,依然无果。
今天,我从http://www.qtcentre.org/archive/index.php/t-35000.html 网页上得到了启发,主要是这句话:“ I forgot the UI file in the transition from a QMainWindow class to a QWidget class.”我在XML Editor中查阅了我的widget.ui文件,发现我的ui文件是这样的:
我看到class标签的值是GoToCellDialog,而整个XML文件中并没有显著的地方提及Widget这个类名。我在Qt Designer中,将整个widget的objectName修改成为Widget,然后编译,成功!
此时,widget.ui文件的前几行内容如下:
- invalid use of incomplete struct "Ui::Widget" 解决方法
- invalid use of incomplete struct "Ui::Widget" 解决方法
- 解决QT:forward declaration of 'struct Ui::xxx';invalid use of incomplete struct "Ui::Widget" 等莫名奇妙错误
- 解决QT:forward declaration of 'struct Ui::xxx';invalid use of incomplete struct "Ui::Widget" 等莫名奇妙错误
- invalid use of incomplete type ‘struct Ui::mydlg
- invalid use of incomplete type ‘struct QLineEdit’
- QT错误:error: invalid use of incomplete type 'struct QScrollBar'
- QT中invalid use of incomplete type 'struct QHostAddress'
- invalid use of incomplete type struct 或者是class的解决办法
- invalid use of incomplete type struct 或者是class的解决办法
- invalid use of incomplete type struct 或者是class的解决办法
- invalid use of incomplete type 报
- 关于提示:invalid use of incomplete type
- invalid use of incomplete type 'class QWidget'
- unordermap 错误 invalid use of incomplete type
- invalid use of incomplete type 'class-Ui-Widge't的解决办法
- c++ class forward declaration and invalid use of incomplete type
- g++ 错误error: invalid use of incomplete type
- Delphi调用其他应用程序
- 抓取网址中的信息(需要解码的)
- Delphi中提示“尚未调用CoInitialize错误”的解决方法
- Scala学习笔记(二) - 环境配置
- c#正则表达式过滤特殊字符
- invalid use of incomplete struct "Ui::Widget" 解决方法
- 关于jqgrid下treeGrid的插件配置
- sencha touch 2.0 中icon里的57 72 114 144是什么意思
- 10g添加归档目录时报错:ORA-16179
- 如何把大部分表中的数据迁移到另一个数据库中
- 产品经理的核心四问
- android 布局大全
- Server(Admin) start is failing in WLST as outofmemory error permgen space for weblogic 12c
- sizeof详解