Saturday, January 4, 2014

Qt ERROR: mainwindow.h:4:23: error: QMainWindow: No such file or directory

# generate make file
$ /opt/Qt5/5.2.0/gcc/bin/qmake -spec linux-g++ -o Makefile torii.pro




# generate ui_mainwindow.h from mainwindow.ui
$ /opt/Qt5/5.2.0/gcc/bin/uic ./mainwindow.ui -o ui_mainwindow.h

# build
$ make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -fPIE -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/opt/Qt5/5.2.0/gcc/mkspecs/linux-g++ -I. -I. -I/opt/Qt5/5.2.0/gcc/include -I/opt/Qt5/5.2.0/gcc/include/QtGui -I/opt/Qt5/5.2.0/gcc/include/QtCore -I. -o mainwindow.o mainwindow.cpp
In file included from mainwindow.cpp:1:
mainwindow.h:4:23: error: QMainWindow: No such file or directory
mainwindow.cpp:4:22: error: QStatusBar: No such file or directory
In file included from mainwindow.cpp:1:
mainwindow.h:12: error: expected class-name before ‘{’ token
mainwindow.h:13: error: ISO C++ forbids declaration of ‘Q_OBJECT’ with no type
mainwindow.h:15: error: expected ‘;’ before ‘public’
mainwindow.cpp:7: error: prototype for ‘MainWindow::MainWindow(QWidget*)’ does not match any in class ‘MainWindow’
mainwindow.h:12: error: candidates are: MainWindow::MainWindow(const MainWindow&)
mainwindow.h:12: error:                 MainWindow::MainWindow()
make: *** [mainwindow.o] Error 1

__fix__
The QMainWindow exists in the QtWidgets directory, so add the following to the Makefile (perhaps there's a way to add this to the .pro file):
-I/opt/Qt5/5.2.0/gcc/include/QtWidgets
 ...
 g++ -c -pipe -O2 -Wall -W -D_REENTRANT -fPIE -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/opt/Qt5/5.2.0/gcc/mkspecs/linux-g++ -I. -I. -I/opt/Qt5/5.2.0/gcc/include -I/opt/Qt5/5.2.0/gcc/include/QtGui -I/opt/Qt5/5.2.0/gcc/include/QtCore -I. -o mainwindow.o mainwindow.cpp

No comments:

Post a Comment