[Solved] New Qt Gui project from QtCreator does not compile
I am unable to port my Qt4 programs to Qt5 because of include files not found.
QT += widgets does NOT fix this.
Then I tried creating a blank Qt Gui app from QtCreator and it does not compile either.
I did not type any code, all code is generated by QtCreator.
It can't find QMainWindow.
This is Qt 5.0.1 for Linux 64bit pre-built binary on Ubuntu 12.04.
Does anyone have a clue on what I'm doing wrong?
Tell us what error messages are you getting, check if your project is properly configured, whether Kits are set up, etc. Can you compile Qt4 apps without problems, or is this not working, too?
Thanks for looking into this, I'll rephrase.
It's real easy to reproduce this problem.
- Start QtCreator (/opt/Qt5.0.1/Tools/QtCreator/bin/qtcreator)
- File / New File or Project
- Select Applications / Qt Gui Appication and do Choose...
- Choose any name
- I get a list of kits, I choose "Desktop Qt 5.0.1 GCC 64bit" and Debug + Release options
- Then hit Next until I get Finish, accepting defaults
- Now QtCreator has created an empty Qt Gui app
- Build the app with Build All
- Error: QMainWindow: No such file or directory
Oh, and yes Qt 4.8.1 works fine.
Is QMainWindow header included with <QtGui/QMainWindow>, by any chance? If so, it is wrong (in Qt5), and of course a bug. Use just <QMainWindow> or <QtWidgets/QMainWindow> instead.
Can't check myself, I'm not using the prebuild packages, but enjoy building stuff myself with clang :)
IMHO the bug is in the fact that qmake does not add an include for QtWidgets in the Makefile if you put QT += widgets in the .pro file.
I know putting <QtWidgets/QMainWindow> will fix the include issue but it should not be neccessary to put <QtWidgets/...> in your source code if you put QT += widgets in your .pro file.
QtCreator does not put <QtWidgets/...> in it's generated source code so the build of an app generated by QtCreator fails.
As expected, both Qt 5.0.1 (+QtCreator 2.6.2) build from source or the pre-build binaries have the same issue.
Either I misunderstand you, or you misunderstand the nature of qmake.
QT+= widgets adds necessary calls to the Makefile so that libQtWidgets can be included and linked without hassle. You still do need to include the headers in source code. <QMainWindow> should be enough, but maybe something is wrong there.
In my application, if I include <QSqlRecord> I just put #include <QSqlRecord> and not #include <QtSql/QSqlRecord>. This works because I put QT += sql in my .pro file.
qmake adds the extra include path for QtSql, it also add the QtSql library for linking, fine.
I would expect the same behaviour from qmake if I put QT += widgets in my .pro file.
So that I only need to put #include <QMainWindow> in my source code and not #include <QtWidgets/QMainWindow>.
Whoever wrote QtCreator assumes the same as me because (s)he puts #include <QMainWindow> in the generated source code and not #include <QtWidgets/QMainWindow>.
That is why apps generated by QtCreator do not compile on Qt5.0.1.
But I'm repeating myself here.
Report it on "Jira":https://qt-project.org/wiki/ReportingBugsInQt, then.
Thanks. I will.
There was an mkspec directory in my home directory.
This messed things up.