From Qt4 to Qt5, include files not found
-
Hi,
I just installed Qt5 for the second time and I ran into the same issues as the first time, but my main issue at this point are with the include files from my existing Qt4 projects.
I read the page below which describes some incompatibilities between the two versions but I couldn't find the script mentioned there (“fixqt4headers.pl”) which should help fixing the headers.
http://qt-project.org/wiki/Transition_from_Qt_4.x_to_Qt5
Can someone show me what changes need to be made to make old Qt4 projects work with Qt5?
These are the header files used in an old Qt4 project (which used to work with Qt4 of course)
bq. mainwindow.h
#include <QMainWindow>bq. mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QtGui>
#include <QtCore>
#include <QMessageBox>
#include <QString>
#include <QDebug>
#include <QClipboard>bq. main.cpp
#include <QtGui/QApplication>
#include "mainwindow.h"The first warning/Error I see is...
QtGui/QApplication: No such file or directory
Which I solved by changing the include to
#include <QGuiApplication>Any quick solution for to make old projects work on Qt5?
FYI
I have a warning in the Build and Run preferences panel under Qt Versions, see picture.
https://www.evernote.com/shard/s157/sh/151aee4a-2e3c-4b62-a0f3-a1003f04eded/df27a0b720491d547a4a9e7f1f20a205 -
I suppose, in QT5, some of the components have been shifted to widgets.
We may have to add 'QT += widgets' in project (.pro) file, in case we have used QApplication or QFileDialog etc. -
yes in Qt 5 the widgets (Including QApplication) have been moved to QtWidgets include folder. To use this to have to add to the pro file QT += widgets. Also the webkit widgets (if you might need them some day) have been moved to QtWebkitWidgets. Cheers.
-
Thank you all for your replies.
Adding QT += widgets to my .pro file doesn't solve any errors.
Is there a list of the classes that were moved?
Thanks
-
I had the very same problem before, and solved after I re-generated the ui_mainwindow.h file.
Hope this may help you.
-
What do you mean with regenerate the mainwindow.h? Delete it and re-create it?
Thanks
-
you ran qmake after the changes to the pro file?
-
[quote author="fs_tigre" date="1356702364"]What do you mean with regenerate the mainwindow.h? Delete it and re-create it?
Thanks[/quote]
Yes, because there're some include commands in it.
-
My solution was to regenerate a project file (.pro). Through away the old one, including the makefiles. Then generate a new one in QtCreator 2.6.1. Add all the files you need and it works fine. As mentioned above the new project file includes the Qt += Widgets, but there is also some sort of prefix to it.
It solved my problems, but with QtCreator 2.6.1 I also needed to install the gdb debugger again because it crashed big time.
Might be better next time if they release a new big release after the holidays ;-)
greetz -
I re-generated the .pro file and it did fix some of the errors but I still have some.
QtGui/QApplication: No such file or directory
variable 'QApplication a' has initializer but incomplete type
Is there a list of classes that have changed/relocated?
This should be easer than this.
Thanks
-
Hi fs_tigre,
This page and its links describe the changes in Qt 5: http://qt-project.org/doc/qt-5.0/qtdoc/portingguide.html ; new features are in http://qt-project.org/doc/qt-5.0/qtdoc/whatsnew.html
There's no dedicated list of relocations, but AFAIK, they are:
- QWidget (and all it subclasses) and QApplication moved from <QtGui> to <QtWidgets>
- QSound moved from <QtGui> to <QtMultimedia>
- The Qt Mobility framework was split up, and its classes were distributed across different modules in Qt 5
-
Thanks a lot for the links, I made the changes recommended and still endup with a few problems, in fact for some reason when I try to open the from file (mainwindow.ui) Qt5 crashes.
I'm currently downloading Qt4 from Nokia, I will use Qt4 for existing projects.
Thank you all very much.
-
Here is my novice proposition:
@$ cat qt4.sh
#!/bin/bashset -e
for a in *.{cpp,h}; do
if [ -f $a ]; then
sed 's/^#include <QtGui>/#include <QtWidgets>/' $a > /tmp/$a~;
sed 's/^#include </#include <QtWidgets//' /tmp/$a~ > $a; rm /tmp/$a~; fi; doneqmake -project
cat >> *.pro <<-stop
CONFIG=qt
QT += widgets
stop
qmake *.pro
make@
you put this in .. and run it from the project's directory:
@. ../qt4.sh@ -
Update:
For me this problem was MAGICALLY solved after...
-deleting the .pro.user file
-opening the project with with Qt4
-finally opening it with Qt5and everything was magically solved, no manual modifications. Don't ask me why, but I did this to two of my old projects and they are now working in Qt5, without me moving a finger.
Side Notes:
What I noticed is that if you delete the old Qt4 .pro file and then try to open it with Qt5 it will not work it looks like as long as you have the old Qt4 .pro file Qt5 will take care of the header files for you.Thanks
-
I have also faced this problem. It was solved by adding this line in .pro file:
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
Try it, It will work hopefully....
-
Here is my permanent fix.
1- Change <QtGui/WidgetName> to <QtWidgets/WidgetName>
2- Fix any other includes individually, for instance if you compile and get an error that says unknown type name 'QLabel', include <QLabel>, than compile again to see what other includes are missing, make the proper includes until you don't see any other error.
3- Open the .pro file and add QT += widgets at the end of the file.
4- Done
-
Please help me with header define script solved qt 5.2
thax & thax
#define SL_FILESTORAGEDIR
static QString fileStorageDir(void) { lmcSettings settings;
QString path = QDir::toNativeSeparators(QDesktopServices::storageLocation( QDesktopServices::DocumentsLocation) + “/“SL_FILESTORAGEDIR); path = settings.value(IDS_FILESTORAGEPATH, path).toString(); return path; }