Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

qmake doesn't invoke uic

I'm aware that there is a couple of questions asked online on similar issues but unfortunately none of them helped me solving this relatively simple-looking one, as the title suggests.

I set up a minimal Qt project in which the problem occurs:

├── main.cpp
├── mainwindow.ui
└── qt.pro

main.cpp:

#include <QtWidgets/QtWidgets>
#include "ui_mainwindow.h"

int main () {
    return 0;
}

qt.pro:

TEMPLATE = app
TARGET = qt-qmake-uic-problem
INCLUDEPATH += .

# Input
FORMS += mainwindow.ui
SOURCES += main.cpp

The file mainwindow.ui is the default MainWindow Form provided by Qt Creator.

Now if I run

qmake qt.pro

then a Makefile is created causing this error when make gets executed:

[developer@kdb qt-qmake-uic-problem]$ make
g++ -c -pipe -O2 -march=i686 -mtune=generic -O2 -pipe -fstack-protector-strong -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I. -I. -isystem /usr/include/qt -isystem /usr/include/qt/QtGui -isystem /usr/include/qt/QtCore -I. -I/usr/lib/qt/mkspecs/linux-g++ -o main.o main.cpp
main.cpp:2:28: fatal error: ui_mainwindow.ui: No such file or directory
 #include "ui_mainwindow.h"
                            ^
compilation terminated.
make: *** [Makefile:298: main.o] Error 1

According to my best knowledge ui_mainwindow.h must be generated either by qmake or by the Makefile - not by myself invoking uic manually. I must note that something similar happens with moc as well and doing my research I haven't found an explanation neither in the documentation nor in similar issues, although it would be strange if this installation of qmake were broken - I'm running Arch Linux and got Qt SDK from the default repository.

Thank you very much for your help in advice!

like image 512
Kuklin István Avatar asked Oct 15 '25 16:10

Kuklin István


1 Answers

Assuming you are using QT-5:

If you want to use UI elements linke a QMainWindow or other QT widgets, you need to enable widgets generally in your project configuration:

QT += widgets

This then activates the processing of the FORMS content like mainwindow.ui in your example, and causes that your code gets linked with the correct libraries.

See also here: http://doc.qt.io/qt-5/qtwidgets-index.html

like image 170
feddischson Avatar answered Oct 18 '25 09:10

feddischson