Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. From Qt4 to Qt5, include files not found
Forum Updated to NodeBB v4.3 + New Features

From Qt4 to Qt5, include files not found

Scheduled Pinned Locked Moved General and Desktop
17 Posts 9 Posters 100.6k Views 1 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.
  • F Offline
    F Offline
    fs_tigre
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sanjaysampat
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        b1gsnak3
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fs_tigre
          wrote on last edited by
          #4

          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

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

            I had the very same problem before, and solved after I re-generated the ui_mainwindow.h file.

            Hope this may help you.

            1 Reply Last reply
            0
            • F Offline
              F Offline
              fs_tigre
              wrote on last edited by
              #6

              What do you mean with regenerate the mainwindow.h? Delete it and re-create it?

              Thanks

              1 Reply Last reply
              0
              • B Offline
                B Offline
                b1gsnak3
                wrote on last edited by
                #7

                you ran qmake after the changes to the pro file?

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  liuyanghejerry
                  wrote on last edited by
                  #8

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

                  1 Reply Last reply
                  0
                  • JeroentjehomeJ Offline
                    JeroentjehomeJ Offline
                    Jeroentjehome
                    wrote on last edited by
                    #9

                    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

                    Greetz, Jeroen

                    1 Reply Last reply
                    0
                    • F Offline
                      F Offline
                      fs_tigre
                      wrote on last edited by
                      #10

                      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

                      1 Reply Last reply
                      0
                      • JKSHJ Offline
                        JKSHJ Offline
                        JKSH
                        Moderators
                        wrote on last edited by
                        #11

                        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

                        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                        1 Reply Last reply
                        0
                        • F Offline
                          F Offline
                          fs_tigre
                          wrote on last edited by
                          #12

                          @JKSH

                          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.

                          1 Reply Last reply
                          0
                          • D Offline
                            D Offline
                            doru001
                            wrote on last edited by
                            #13

                            Here is my novice proposition:
                            @$ cat qt4.sh
                            #!/bin/bash

                            set -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; done

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

                            1 Reply Last reply
                            0
                            • F Offline
                              F Offline
                              fs_tigre
                              wrote on last edited by
                              #14

                              Update:

                              For me this problem was MAGICALLY solved after...

                              -deleting the .pro.user file
                              -opening the project with with Qt4
                              -finally opening it with Qt5

                              and 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

                              1 Reply Last reply
                              0
                              • M Offline
                                M Offline
                                mickey
                                wrote on last edited by
                                #15

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

                                1 Reply Last reply
                                0
                                • F Offline
                                  F Offline
                                  fs_tigre
                                  wrote on last edited by
                                  #16

                                  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

                                  http://qt-project.org/doc/qt-5.0/qtdoc/portingcppapp.html

                                  1 Reply Last reply
                                  0
                                  • C Offline
                                    C Offline
                                    ctsiitmail
                                    wrote on last edited by
                                    #17

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

                                    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 Extensions
                                    • Unsolved