The Problem: When a QMainWindow or QDialog's corresponding .ui file has been altered in Qt Designer, the entire project must be cleaned and rebuilt in order for those changes to take effect: make clean
then make
. If the project isn't cleaned first, the changes will not reflect in the executable.
The Project Structure:
./
project.pro
./include/
MainWindow.h
Main.h
./src/
MainWindow.cpp
Main.cpp
./ui/
MainWindow.ui
The Source:
MainWindow.h:
#include <QMainWindow>
#include "ui_MainWindow.h"
class MainWindow : public QMainWindow, private Ui::MainWindow
{
Q_OBJECT
public:
MainWindow();
};
MainWindow.cpp:
#include "MainWindow.h"
MainWindow::MainWindow()
{
Ui::MainWindow::setupUi(this);
}
project.pro:
TEMPLATE = app
CONFIG -= debug release
CONFIG += qt debug_and_release warn_on incremental flat link_prl embed_manifest_dll embed_manifest_exe
QT += xml xmlpatterns
INCLUDEPATH += include/
UI_DIR = include/
FORMS += ui/MainWindow.ui
HEADERS += include/MainWindow.h include/Main.h
SOURCES += src/MainWindow.cpp src/Main.cpp
Note: Include guards and class members have been stripped out for terseness.
Update:
Assuming that we edit MainWindow.ui in Designer, save it, and run a make
, the following shell commands are executed (on a Windows platform; equal commands are executed on a 'nix box too):
QTDIR\bin\uic.exe ui\MainWindow.ui -o include\ui_MainWindow.h
QTDIR\bin\moc.exe ... include\MainWindow.h -o build\moc\moc_MainWindow.cpp
MSVS\bin\cl.exe /c ... -Fobuild\obj\ moc_MainWindow.cpp
MSVS\bin\link.exe ... /OUT:bin\target.exe
The uic
header generator has been run, and the window has been moc'ed. Despite this the window remains unchanged in the executable.
Update #2:
I found these lines in the Makefile:
####### Compile
build\obj\MainWindow.obj: src\MainWindow.cpp
build\obj\main.obj: src\main.cpp
build\obj\moc_MainWindow.obj: build\moc\moc_MainWindow.cpp
Bingo. MainWindow.obj
rightfully depends on MainWindow.cpp
, but not on moc_MainWindow.cpp
. Changing the first line to build\obj\MainWindow.obj: src\MainWindow.cpp build\moc\moc_MainWindow.cpp
rectified this whole issue.
However: the next time I run qmake
it's going to nix me. What can I type in qmake to fix this permanently?
examples/designer/calculatorform
, it works as expected, even after adding yourUI_DIR
andINCLUDEPATH
specification. Does this standard example work for you? If so, you have something to work from/towards. – Matt Wallis