【发布时间】:2012-03-11 01:04:01
【问题描述】:
我正在尝试使用 Qt Creator 从 QMainWindow 显示 QDialog。 QDialog 的名称是 About。默认情况下,我的 MainWindow 和 QDialog 都在命名空间 Ui 中,但是在尝试创建新 About 时出现错误。
MainWindow.h
#include <QMainWindow>
#include "about.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow {
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
protected:
void changeEvent(QEvent *e);
private slots:
void on_actionAbout_activated();
private:
Ui::MainWindow *ui;
Ui::About *about;
};
MainWindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->about = null;
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionAbout_activated()
{
this->about = new Ui::About(this);
this->about->show();
}
错误是:
invalid use of incomplete type ‘struct Ui::About’
这发生在一行中:
this->about = new Ui::About(this);
发生了什么?命名空间 Ui 中是否有一个名为 About 的结构体?
【问题讨论】:
标签: c++ qt namespaces qt4