まず、検索、読み込み、デバッグの多くを行った後に質問を投稿しましたが、問題を解決できません。Qt - エラー:タイプなしの 'MainWindow'の宣言をISO C++が禁じています
私は2つのクラスのMainWindowとControllerを持っていますが、どちらももう一方を含む必要があります。私は再帰的なincludeの問題を転送を使って解決しようとしましたが、うまくいきませんでした。 私は、ネームスペースでフォワードを実装することにいくつか問題があると思います。
両方のクラスのためのコード:(iは、できるだけ多くのコードを短くしようとした)
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtCore>
#include "controller.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void addRadioButtons();
void changeViewQML(QString);
void changeViewXML(QString);
private:
Ui::MainWindow *ui;
controller controllerObj;
};
#endif // MAINWINDOW_H
controller.h
#ifndef CONTROLLER_H
#define CONTROLLER_H
#include <QtCore>
#include "mainwindow.h"
class controller : public QThread
{
public:
controller();
void response_handler(QString);
private:
MainWindow *viewObj;
protected:
void run();
};
#endif // CONTROLLER_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::changeViewQML(QString s)
{
qDebug(s.toAscii());
}
controller.cpp
#include "controller.h"
controller::controller()
{
}
void controller::response_handler(QString responseFilePath)
{
viewObj->changeViewQML(responseFilePath);
}
と私はこのISOのエラーを持っておきます。
ロングコードのため申し訳ありません、およびいずれかの部分が十分に
私はこれを試しましたが、エラーが出ます:不完全な型 'struct Ui :: MainWindow'の無効な使用...私はこの新しいエラーを私の#include "mainwindow.h"をcontroller.cppファイルで解決しようとしましたしかし、それは動作しません! –
大丈夫、申し訳ありませんが、 'MainWindow'と' Ui :: MainWindow'が2つの異なるクラスであることを私は混乱していました。私はあなたの解決策を試してみたら – PeterT
の答えを編集するつもりです。 "ui_mainwindow.h" mainview.cppには以下のコードが含まれています:namespace Ui { class MainWindow:public Ui_MainWindow {}; } //名前空間Ui .... mainviewクラスはQtCreatorによって自動生成されます –