Reputation: 41
I am trying to make a link between my 3 windows , so I put this in my mainwindow.h
:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "video.h"
#include "flightdata.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void openNewWindowVideo();
void openNewWindowData();
private:
Ui::MainWindow *ui;
video *myVideoWindow;
flightdata *myDataWindow;
};
#endif // MAINWINDOW_H
And this in my implementation:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->actionVideo,SIGNAL(triggered()),this,SLOT(openNewWindowVideo()));
connect(ui->actionFlight_data,SIGNAL(triggered()),this,SLOT(openNewWindowData()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::openNewWindowVideo()
{
myVideoWindow = new video();
myVideoWindow->show();
this->close();
}
void MainWindow::openNewWindowData()
{
myDataWindow = new flightdata();
myDataWindow->show();
this->close();
}
This works.
But when O follow the same steps for the 2 other windows ( file.h
+ file.cpp
),
iI get the error : qt error: 'flightdata' does not name a type qt error: 'video' does not name a type
But when I include just first window and not the 2 others , I don't get this problem.
Maybe it is being caused by recursion.
Upvotes: 1
Views: 2300
Reputation: 1899
As far as I can tell, there are potentially two things that may be wrong:
Pre-processor/MACRO
If you created the other windows with QtCreator/Designer, the #ifndef macros should be unique. Meaning, video.h should have something like:
#ifndef VIDEOWINDOW_H
#define VIDEOWINDOW_H
instead of the default
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
These #ifndef MACROS are intended to help include the contents of the header file once and only once.
Missing include paths
Also, if you're using QtCreator, the editor should display #include "video.h" and #include "flightdata.h" as a link (control + left click). If the syntax is underlined red, it means that the project can't find those files.
Then you'll need to check to make sure that the files are either in your project folder or add have the path to those files added in the qmake variable INCLUDEPATH of your pro file.
# e.g.
INCLUDEPATH += ../myflightdata ../myvideofiles
Upvotes: 0
Reputation: 40492
Don't include your other classes in header files. Include them in source files only.
If you for some reason need to use another class in a header of other class, use forward declaration instead of include.
Header:
// no include for 'video.h'
class video;
class MainWindow : public QMainWindow {
//...
video *myVideoWindow;
};
Source:
#include "video.h"
//...
Upvotes: 1