Solved Convert Qt 4.x project to Qt 5.3 . Any tips?
-
I did add in these 2 lines in the header just to see if I could compile after that .(It all compiles in Qt 4.8)
#include <QLineEdit>
#include <QDoubleSpinBox>
So many other errors popped up after I did that that I wondered if I was doing the conversion correctly.
mainwindow.cpp:22: error: invalid use of incomplete type 'class QDesktopWidget'
QRect screenGeometry = QApplication::desktop()->screenGeometry();
^
ui_mainwindow.h:14: from ./ui_mainwindow.h:14,
/usr/include/arm-linux-gnueabihf/qt5/QtWidgets/qapplication.h:61: error: forward declaration of 'class QDesktopWidget'
class QDesktopWidget;
^
mainwindow.cpp:214: error: 'QMessageBox' was not declared in this scope
QMessageBox msgBox;
^
/usr/include/arm-linux-gnueabihf/qt5/QtWidgets/qapplication.h:61: error: forward declaration of 'class QDesktopWidget'
class QDesktopWidget;
^ -
@Lineaxe
Without seeing the .pro file, all that can be said is you're missing some include file(s) somewhere.The QDesktopWidget and QMessageBox include files are included from QWidgets so do you have this in your .pro INCLUDEPATH?
-
@KeithS No need to have QWidgets in INCLUDEPATH. To use widget related classes you need
QT += widgets
in the PRO file.
-
In which case I guess the OP's test:
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
is not correct?
-
@KeithS It is correct. The problem is probably: old style includes for Qt headers. These must be changed to e.g.:
#include <QMessageBox>
-
I checked all my headers they are all in #include <Qheadername> format . The only ones in double quotes are the ones from my own classes ,etc .
-
mainwindow.cpp:214: error: 'QMessageBox' was not declared in this scope QMessageBox msgBox;
Did you include QMessageBox in mainwindow.cpp?
-
Well , I got 183 errors flagged , many are the same error . But they flag
Desktop , messagebox, and so on.. I thought about what you mentioned jsulm , so
I put
#include <QtWidgets> into mainwindow.cpp and all my other .cpp files that were accessing widgets and it solved the problem of all those errors in the cpp files. It seems then to convert from Qt 4.x over to Qt 5.3, overall , all I needed to do was add this line in to the appropriate .cpp files . I didn't need to declare separate headers , as I was testing out above.
I had to replace some .toAscii() over to .toLatin1(). in some of the Qstrings used in program.
(requesting another point, by the way who passes out them points ?) -
That's the wrong solution. What you did there is pull in all headers from the widgets module which is not what you should do since it will make your build time longer as all headers will have to be parsed.
Just include what you use.
-
Ok , I have actually just read something along that line. It makes sense to me to only put in the ones that are flagged.. Anyhow, doing it that way seems to have a use. It shows that the code WILL compile in Qt 5.3 . By commenting it out will show the actual headers that are needed for each .cpp file. Then I can add them in one at a time . Very slow to compile however. Thanks again I am marking this one as solved since it all compiles now.
Also in this version I seem be be able to use the debugger on the arm computer :) The older version just kept freezing up on me when I went deeper into the code.