Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Convert Qt 4.x project to Qt 5.3 . Any tips?
Qt 6.12 LTS is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 4 Posters 6.9k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #4

    Hi,

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

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • L Offline
      L Offline
      Lineaxe
      wrote on last edited by
      #5

      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;
      ^

      K 1 Reply Last reply
      0
      • L Lineaxe

        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;
        ^

        K Offline
        K Offline
        KeithS
        wrote on last edited by
        #6

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

        jsulmJ 1 Reply Last reply
        0
        • K KeithS

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

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #7

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

          QT += widgets
          

          in the PRO file.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          K 1 Reply Last reply
          0
          • jsulmJ jsulm

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

            QT += widgets
            

            in the PRO file.

            K Offline
            K Offline
            KeithS
            wrote on last edited by
            #8

            @jsulm

            In which case I guess the OP's test:

            greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

            is not correct?

            jsulmJ 1 Reply Last reply
            0
            • K KeithS

              @jsulm

              In which case I guess the OP's test:

              greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

              is not correct?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #9

              @KeithS It is correct. The problem is probably: old style includes for Qt headers. These must be changed to e.g.:

              #include <QMessageBox>
              

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • L Offline
                L Offline
                Lineaxe
                wrote on last edited by
                #10

                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 .

                1 Reply Last reply
                0
                • jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #11
                  mainwindow.cpp:214: error: 'QMessageBox' was not declared in this scope
                  QMessageBox msgBox;
                  

                  Did you include QMessageBox in mainwindow.cpp?

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    Lineaxe
                    wrote on last edited by
                    #12

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

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #13

                      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.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • L Offline
                        L Offline
                        Lineaxe
                        wrote on last edited by Lineaxe
                        #14

                        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.

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt
                        • Unsolved