"QMainWindow: No such file or directory" error: Compiling using qmake only.
I'm trying to compile a qt project using terminal (Linux) qmake, but I'm getting the follwoing error message:
I tried to follow this manual: https://doc.qt.io/qt-5/qmake-manual.html
mainwindow.h
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
{
Q_OBJECT
public:
MainWindow
(QWidget *parent
= nullptr
);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
mainwindow.cpp
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) , ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
main.cpp
Code:
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
return a.exec();
}
main.pro
Code:
HEADERS += mainwindow.h
SOURCES += mainwindow.cpp
SOURCES += main.cpp
Quote:
[rob@archrob qteste]$ qmake main.pro
[rob@archrob qteste]$ make
g++ -c -pipe -O2 -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -Wall -Wextra -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I. -isystem /usr/include/qt -isystem /usr/include/qt/QtGui -isystem /usr/include/qt/QtCore -I. -I/usr/lib/qt/mkspecs/linux-g++ -o mainwindow.o mainwindow.cpp
In file included from mainwindow.cpp:1:
mainwindow.h:4:10: fatal error: QMainWindow: No such file or directory
4 | #include <QMainWindow>
| ^~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:663: mainwindow.o] Error 1
Re: "QMainWindow: No such file or directory" error: Compiling using qmake only.
Add QT += widgets to your .pro file.
Re: "QMainWindow: No such file or directory" error: Compiling using qmake only.
Quote:
Originally Posted by
d_stranz
Add QT += widgets to your .pro file.
Ok, but now I'm getting this:
[quote][/[rob@archrob qteste]$ make
g++ -c -pipe -O2 -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -Wall -Wextra -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -isystem /usr/include/qt -isystem /usr/include/qt/QtWidgets -isystem /usr/include/qt/QtGui -isystem /usr/include/qt/QtCore -I. -I/usr/lib/qt/mkspecs/linux-g++ -o mainwindow.o mainwindow.cpp
mainwindow.cpp:2:10: fatal error: ui_mainwindow.h: No such file or directory
2 | #include "ui_mainwindow.h"
| ^~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:668: mainwindow.o] Error 1quote]
Re: "QMainWindow: No such file or directory" error: Compiling using qmake only.
Add this line to pro file :
Code:
FORMS += mainwindow.ui
Re: "QMainWindow: No such file or directory" error: Compiling using qmake only.
And next will come the error about "Ui:: MainWindow" class being undefined because the one that -has- been defined has been put into a Qt namespace.