找回密码
 立即注册
收起左侧

《Qt Creator快速入门》2.3.2节出现的问题

1
回复
8622
查看
[复制链接]
累计签到:13 天
连续签到:1 天
来源: 2016-12-28 17:05:29 显示全部楼层 |阅读模式
1Qter豆
本帖最后由 ceiwei 于 2016-12-28 17:38 编辑

按照2.3.2节建好各个文件中的代码,然后运行,出现报错:
error: ui_hellodialog.h: No such file or directory
#include "ui_hellodialog.h"

QT版本为5.2


没有自动生成ui_hellodialog.h头文件


重建一个UI设计师界面解决了上述问题,但新问题又出现了,

In constructor 'HelloDialog::HelloDialog(QWidget*)':
rror: invalid use of incomplete type 'class Ui::HelloDialog'
     ui = new Ui::HelloDialog;
n file included from ..\helloworld\hellodialog.cpp:1:0:
error: forward declaration of 'class Ui::HelloDialog'
     class HelloDialog;          //鏂版坊
error: invalid use of incomplete type 'class Ui::HelloDialog'
     ui->setupUi(this);
error: forward declaration of 'class Ui::HelloDialog'
     class HelloDialog;          //鏂版坊
           ^
运行作者老师的例子就可以运行,但是就算我直接拷贝代码过来也会弧线上述的错误,这是为何呢?


       ^



                  ^



hellodialog.h代码:

#ifndef HELLODIALOG_H#define HELLODIALOG_H
#include <QDialog>
namespace Ui {class HelloDialog;}
class HelloDialog : public QDialog{    Q_OBJECTpublic:    explicit HelloDialog(QWidget *parent = 0);
signals:
public slots:
private:    Ui::HelloDialog *ui;
};
#endif // HELLODIALOG_H

hellodialog.cpp代码:

#include "hellodialog.h"#include "ui_hellodialog.h"HelloDialog::HelloDialog(QWidget *parent) :    QDialog(parent){    ui=new Ui::HelloDialog;    ui_>setupUi(this);}
main.cpp代码:

#include<QApplication>#include"hellodialog.h"int main(int argc. char argv[]){    QApplication a(argc, argv);    HelloDialog w;    w.show();    return a.exec();}

工程文件代码:


QT       += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = helloworldTEMPLATE = app
HEADERS += \    hellodialog.h
SOURCES += \    hellodialog.cpp \    main.cpp
FORMS += \    helloworld.ui


回复

使用道具 举报

累计签到:1568 天
连续签到:1 天
2016-12-31 10:14:30 显示全部楼层
第3版源码已经上传,请到社区下载页面下载。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了