[Solved] New Qt Gui project from QtCreator does not compile
-
wrote on 4 Feb 2013, 09:08 last edited by
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?
-
wrote on 4 Feb 2013, 11:44 last edited by
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
Kind regards,
Wino. -
wrote on 4 Feb 2013, 11:54 last edited by
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 :)
-
wrote on 4 Feb 2013, 12:33 last edited by
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.
-
wrote on 4 Feb 2013, 12:37 last edited by
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.
-
wrote on 4 Feb 2013, 12:58 last edited by
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.
-
wrote on 4 Feb 2013, 13:31 last edited by
Thanks. I will.
-
wrote on 4 Feb 2013, 16:39 last edited by
There was an mkspec directory in my home directory.
This messed things up.
1/12