I have the very simple following code:
main.cpp
#include "ui_library_browser.h"
#include <QtGui/QApplication>
#include "StartWindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
StartWindow w;
w.show();
return a.exec();
}
StartWindow.h
#ifndef STARTWINDOW_H_
#define STARTWINDOW_H_
#include <qwidget>
#include "MainWindow.h"
class StartWindow : public QWidget
{
Q_OBJECT
public:
StartWindow();
~StartWindow();
MainWindow main_window; //<-- Problem
};
#endif
MainWindow.h
#ifndef MAINWINDOW_H_
#define MAINWINDOW_H_
#include <qdialog.h>
#include "StartWindow.h"
class MainWindow : public QDialog
{
Q_OBJECT
public:
MainWindow();
~MainWindow();
};
#endif
I get the following errors:
moc_MainWindow.cpp
StartWindow.h(14): error C2146: syntax error : missing ';' before identifier 'main_window'
StartWindow.h(14): error C4430: missing type specifier – int assumed. Note: C++ does not support default-int
StartWindow.h(14): error C4430: missing type specifier – int assumed. Note: C++ does not support default-int
I've written a few C++/Qt apps before, but I'm bamboozled by this!
Thanks in advance!
Best Answer
You have circular dependencies on your headers. Remove the
#include "StartWindow.h"
from yourMainWindow.h
file.