Reputation: 236
I created a app in QT Creator and am trying to build a distributable mac app with it, but I keep getting this error:
./mainwindow.h:4:10: fatal error: 'QMainWindow' file not found
#include <QMainWindow>
^
1 error generated.
First I cd
to the projects build directory folder and invoke the statically compiled version of qmake:
/Volumes/StaticQT/qt-everywhere-opensource-src-5.8.0/qtbase/bin/qmake -config release /PathOfFoo.pro
I then run make
and receive the error as highlighted above. I've tried adding:
INCLUDEPATH = "/Volumes/BackupSG/StaticQT/qt-everywhere-opensource-src-5.8.0/qtbase/include"
to the .pro file to specify where it should draw stuff from. I'm not sure if it's that qmake/make isn't finding the right dir or what.
Note: I also have the same issue with the non-static version.
Any ideas on how to fix this? I've read several other questions about this, but they are mostly all for older versions of qt.
Edit: The original problem was solved by the answer of adding QT += widgets
to the .pro file, and got further into compilation before it ran into another similar issue:
/$paths/ui_mainwindow.h:13:10: fatal error: 'QtGui/QAction' file not found
#include <QtGui/QAction>
^
1 error generated.
Per the comments on the accepted answer on this question, the step at which make fails does have -I<PATH_TO_QT5_INSTALL>/QtWidgets
.
Upvotes: 0
Views: 604
Reputation: 98505
The problem has nothing to do with static Qt. Your project file doesn't include the necessary widgets
module:
# Foo.pro
QT += widgets
TEMPLATE = app
TARGET = Foo
SOURCES += ...
HEADERS += ...
# etc
After fixing this, re-run qmake as such changes to the project file are not automatically detected.
If you wish to support Qt 4, you'll want something like:
QT += gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
I've tried adding
INCLUDEPATH = "/Volumes/BackupSG/StaticQT/qt-everywhere-opensource-src-5.8.0/qtbase/include"
Don't do that. You've got qmake to do it for you. If it doesn't, it merely means your project file is broken.
Finally, the path <QtGui/QAction>
is invalid. It's a holdover from Qt 4, but even there it wasn't necessary: it should have simply been <QAction>
. Change it to <QAction>
and you'll be set. If that file is generated (it looks like it), you're attempting to reuse uic
output from Qt 4: don't do that. Qt 5's uic
won't ever generate that line. Add the .ui
files to the project, and get rid of the ui_foo.h
files:
# Foo.pro
...
FORMS += foo.ui bar.ui
As a rule of thumb, your project should only ever have two forms of Qt includes:
#include <QtModule>
#include <QClass>
#include <QtModule/QClass> // Don't! Use <QClass> instead
#include <QtModule/qclass.h> // Don't! Use <QClass> instead
#include <qclass.h> // Don't! Use <QClass> instead
Note that Qt's own sources and generated output break that rule, but it's done for technical reasons that do not apply to the code you yourself write.
Upvotes: 1