PDA

View Full Version : "QMainWindow: No such file or directory" error: Compiling using qmake only.



robgeek
19th January 2020, 22:28
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

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();

private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_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;
}

main.cpp

#include "mainwindow.h"

#include <QApplication>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}

main.pro

HEADERS += mainwindow.h
SOURCES += mainwindow.cpp
SOURCES += main.cpp


[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

d_stranz
20th January 2020, 01:15
Add QT += widgets to your .pro file.

robgeek
20th January 2020, 01:55
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]

Lesiok
20th January 2020, 08:14
Add this line to pro file :
FORMS += mainwindow.ui

d_stranz
20th January 2020, 16:06
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.