Convert Qt 4.x project to Qt 5.3 . Any tips?



  • Hi I am reading articles online and testing out the steps they describe. Still I am getting errors. Is there some easier way of going about this that I don't know about?



  • @Lineaxe

    What steps? What errors?



  • here are some of the articles I have found on it . I had hoped it would be easy to upgrade your source :)

    https://wiki.qt.io/Transition_from_Qt_4.x_to_Qt5
    http://www.ics.com/blog/porting-desktop-applications-qt-4-qt-5
    I already have the following in my .pro file greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    on compile in Qt 5.3 I got 2 warnings
    overriding recipe for target 'moc_MythreadName.cpp'
    ignoring old recipe for target 'moc_MythreadName.cpp'
    I got these both these errors 2x each , I suspect more will show up after I get them resolved.
    QLineEdit not declared
    QDoubleSpinBox not declared


  • Lifetime Qt Champion

    Hi,

    Do you have the corresponding includes in the files where you get the complain from ?



  • 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?


  • Moderators

    @KeithS No need to have QWidgets in INCLUDEPATH. To use widget related classes you need

    QT += widgets
    

    in the PRO file.



  • @jsulm

    In which case I guess the OP's test:

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    is not correct?


  • Moderators

    @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 .


  • Moderators

    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 ?)


  • Lifetime Qt Champion

    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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.