Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. The Lounge
  4. Experience porting Qt4 project to Qt5
QtWS25 Last Chance

Experience porting Qt4 project to Qt5

Scheduled Pinned Locked Moved The Lounge
9 Posts 4 Posters 4.7k Views
  • 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.
  • S Offline
    S Offline
    Serenity
    wrote on last edited by
    #1

    Hi all together,

    As everybody of you know, the Qt Company will extend the support of Qt4 over one year and will also release a new bug fix version.
    To be not the last one, who ports his project to Qt5, I now started to do that and want to share my experiences with you on this, let me say, adventure.

    Let's see first, what kind of project I have:
    It's a Qt Widgets project, including no QML code with totaly approx. 30k LLOC, compiled with MinGW, gcc version 4.6.3.

    My result version should be Qt5.3 with gcc version 4.8.2

    It is using Qt Webkit, Qt Core, Qt Widgets (in Qt4, it was QtGui), QtNetwork, Qt XML and Qt SVG.
    Before QtSerialPort was integrated , I used it as an additional library. I am also using QGraphicsView for painting items.

    I have also other libraries:

    • Quazip (Qt4 library for easy reading/writing ZIP files)
    • QtSingeApplication
    • LibExif
    • LibTiff
    • GDAL

    I also want, that my software works on Linux and Windows. I will start first with windows, because I think, that if it works on windows, Linux doesn't seam to be such a problem.

    First compiling the libraries:
    So as the EABI of gcc 4.6 to 4.8 have changed, I have to compile all libraries again. That was not so complicated, but it took a lot of time (because it doesn't work immediately). Quazip, depending before on Qt4, can be easily compiled with Qt5, so that wasn't quite hard.
    I removed QtSingleApplication out of my project, because it is not so important at the beginning.

    Porting project from 4 to 5

    So, that was quite harder.
    First, I replaced all Qt4 modules to Qt5 in my project file:
    @QT += core gui webkit network xml svg@

    In Qt5, it looks like:
    @QT += core widgets webkitwidgets network xml svg serialport@

    Also, every #include <QtGui> have to be changed to #include <QtWidgets>
    Also, I replaced all #include <QtWebKit> with #include <QtWebKitWidgets>

    Then, when I am compiling my code, a lot of new errors and warning appears.
    Let me give some example.
    @QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)@
    have to be changed to
    @QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)@

    Every converting QString toAscii have to be changed to toLatin1

    The next and last thing was something with my GraphichsItem. The Contructor for example of QGraphicsLineItem doesn't include any more GraphicsLineItem(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0), so I have ti use scene->addItem(item) after creating my item.

    So that was first all. The code compiles and the program started.

    *Starting program in Qt5

    So, let first see, what is working and what is not working.

    My program starts with some confusing error:

    First, it seams, that it was not able anymore to open some of my files:
    @QIODevice::write: device not open
    QIODevice::write: device not open
    QIODevice::write: device not open@

    Then, a unknown warning (I think, it comes from any QtWebView Widget) was shown:

    @QSslSocket: cannot resolve TLSv1_1_client_method
    QSslSocket: cannot resolve TLSv1_2_client_method
    QSslSocket: cannot resolve TLSv1_1_server_method
    QSslSocket: cannot resolve TLSv1_2_server_method
    QSslSocket: cannot resolve SSL_select_next_proto
    QSslSocket: cannot resolve SSL_CTX_set_next_proto_select_cb
    QSslSocket: cannot resolve SSL_get0_next_proto_negotiated@

    And as I see, no QtWebView seams to work anymore. That's bad, but I will fix it. I am only seeing a white screen. I have 2 kinds of QtWebView:
    The first one is still opening a local html file on the desktop. That was quite also hard in Qt4, because Qt4 in Windows has problems to open relative paths in html files (for example images). I wrote a routine, that replace all relative paths to absolute ones.
    The second QWebView is only opening a OpenLayers Webmap located online anywhere. That also doesn't work.

    QtWidgets seams to work, except of my QGraphicsView. There are some of my functions, that are not working anymore properly (don't know why at the moment).

    Also, some created files with the Qt4 version can't be opened any more with the Qt5 versions. It seams to be, that my old files are broken. I have to cheack the routine, how the file was opened.
    But as I see, nearly every created file in my project, created with Qt4, can't be opened properly anymore with my Qt5 version. That's really really bad.

    Let us come to things, what are working if you ported quickly as I did:

    QtSerialPort is working without any problems, I have also done nothing and have only to use the module available in Qt5
    All my widgets (except the ones, i mentioned before), are still working. Also, it seams, that all my connected signals and slots are not broken.

    Quazip also works.

    QNetworks seams also to work. I have a textfile on a webserver and it could be downloaded and showed in my program.

    QtSvG also works. My graphics in my QtGraphicView could be displayed and scaled without any problem.

    That's it for the first.

    If you have any questions or suggestions, please write it down. I will later write more about it, when I find the bugs and the functions, that doesn't work anymore.

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

      Hi,

      Did you took a look at the Porting Guide and API changes ? There are some useful hints in there. There might be some things that are missing but it should already help.

      For you problems you should also take a look at the "bug report system":http://bugreports.qt-project.org , you might be hitting something

      [edit: corrected my link]

      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
      • S Offline
        S Offline
        Serenity
        wrote on last edited by
        #3

        Thanks SGaist for your help. I am only sharing my experience and maybe, there are other people, who are doing that well or maybe see, that it is not so hard to port their software also to Qt5. As I know from Berlin, a lot of people are still using Qt4, maybe (as me) because there are afraid to port it (and why changing a running system?).

        They have done more than only written in the porting guide, as I know. If found out, that the StandardPaths have been changed. That's the reason, why my QGraphicsView didn't work well, because I need some data from there.

        Now, nearly everything is working. In Linux, the UI is not in the OS style, but that is not so important. The last thing, what is not working is reading some files correctly. As I am using QDataStream, I forgot to add the version. Maybe that is the reason, but it could be also something else. I will post it, if I found out, why.

        I have already posted some bugs, which I found during my development, but as I see, nothing of them was fixed. I think, nobody tested it, because I mostly reported them for Qt4.
        And SGaist: Your link is not working ;) You forgot an 's': http://bugreports.qt-project.org

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Apart from the official "porting guide":http://qt-project.org/doc/qt-5/portingguide.html, there is the Wiki describing a lot of details on the practical side: "link":http://qt-project.org/wiki/Transition_from_Qt_4.x_to_Qt5.

          In general, it all boils down to specific use cases. For some, the porting is very easy. for others - it requires more effort.

          I've ported several applications and libraries, most of the stuff went pretty smoothly. The biggest project was close to 40 kLOC and porting it took me about 2 hours.

          (Z(:^

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Serenity
            wrote on last edited by
            #5

            So, the part with setting the version of the datastream was correct.

            But now, I have such non-reproducible problems, that makes it quite hard to get my completely program to work.

            First thing: I have a QDialog, which is creating a snapshot of an OpenLayer Maps, read the geo points out and then close it.
            That works perfectly on Qt4.8. In Qt5.3, I get a segmentation fault on a QDialog exec() function. So, that might be wrong, so I am looking for the error and I found it. When I close my snapshot dialog, directly after doing some Javascript functions (getting the koordinates) and calculations on the QtWebKitWidget, the program crashes, BUT when I set a timer, which close the dialog after 500ms, it works. It is not the best workaround, but it is better than crashing...

            next thing: showFullscreen() on Linux doesn't work properly. Sometimes, it seams, that it using to create the widget the minimum size hint instead of put all the widget on the entire screen. Then, also it removes the Qt Window Modality, so QDialog::exec() doesn't "lock" anymore the parent window/widget.

            Also, QString::append(char) is not working in Qt5 as in Qt4. But why did they changed something in that class? I don't know...

            I think, I will find more and more problems because of porting my program to Qt5. I recommend everyone, who have a working Qt4 application without any problems, not porting it to Qt5. I have to do that, because parts of my classes and modules will be used in a new QML project. Therefore it have to work in Qt5.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Serenity
              wrote on last edited by
              #6

              I have now some points to add after a while and can also recommend everyone:

              Don't port your application if you don't need it!

              I have now a lot of problems which are bugs in Qt5. For example: Closing a QWebWidget before completely loading a website causes to a segmentation fault. That's something, I can't solve at the moment and is a huge problem for me and my application. Nevertheless, I try something else, but it costs so much time, that I would never ever recommend someone to do a port from 4 to 5.

              There are a lot of other things, that doesn't work probably and have to be fixed by a workaround. Simply "Compile your code and change some header or expressions" is not the true. If you have a huge project, you also have to take huge efforts to switch.

              "Report a bug" is something, that I also do, but until today, nothing was fixed what I have reported or I am observing. One time, I talked to Lars Knoll and it seams, that they will take more efforts in mobile platforms, Qt modules for the commercial license or QtQuick, but not for extending the C++ Module with features or bugfix/improve existing modules.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Serenity
                wrote on last edited by
                #7

                I have now some points to add after a while and can also recommend everyone:

                Don't port your application if you don't need it!

                I have now a lot of problems which are bugs in Qt5. For example: Closing a QWebWidget before completely loading a website causes to a segmentation fault. That's something, I can't solve at the moment and is a huge problem for me and my application. Nevertheless, I try something else, but it costs so much time, that I would never ever recommend someone to do a port from 4 to 5.

                There are a lot of other things, that doesn't work probably and have to be fixed by a workaround. Simply "Compile your code and change some header or expressions" is not the true. If you have a huge project, you also have to take huge efforts to switch.

                "Report a bug" is something, that I also do, but until today, nothing was fixed what I have reported or I am observing. One time, I talked to Lars Knoll and it seams, that they will take more efforts in mobile platforms, Qt modules for the commercial license or QtQuick, but not for extending the C++ Module with features or bugfix/improve existing modules.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  maximus
                  wrote on last edited by
                  #8

                  [quote author="Serenity" date="1416812336"]
                  Don't port your application if you don't need it!

                  I have now a lot of problems which are bugs in Qt5. For example: Closing a QWebWidget before completely loading a website causes to a segmentation fault. That's something, I can't solve at the moment and is a huge problem for me and my application. Nevertheless, I try something else, but it costs so much time, that I would never ever recommend someone to do a port from 4 to 5.
                  [/quote]

                  I too have this problem with the QWebView being closed while loading a page causing a Seg fault, only happening on OS X (windows version works fine). Using Mavericks Qt 5.4.

                  I would recommend to always upgrade to the latest Qt version. Yes it takes some time and work, but you ensure to have an easy time and small upgrade each Qt Version. If you wait too long to upgrade, it can become a bit messy. Also you are helping develop Qt by keeping it active and submitting bugs.

                  Just ported from 5.3.2 to 5.4
                  Only bug I had, some SSL errors now appear on the OS X version in the console ouput..
                  @QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated@
                  Good luck


                  Free Indoor Cycling Software - https://maximumtrainer.com

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    maximus
                    wrote on last edited by
                    #9

                    [quote author="Serenity" date="1416812336"]
                    Don't port your application if you don't need it!

                    I have now a lot of problems which are bugs in Qt5. For example: Closing a QWebWidget before completely loading a website causes to a segmentation fault. That's something, I can't solve at the moment and is a huge problem for me and my application. Nevertheless, I try something else, but it costs so much time, that I would never ever recommend someone to do a port from 4 to 5.
                    [/quote]

                    I too have this problem with the QWebView being closed while loading a page causing a Seg fault, only happening on OS X (windows version works fine). Using Mavericks Qt 5.4.

                    I would recommend to always upgrade to the latest Qt version. Yes it takes some time and work, but you ensure to have an easy time and small upgrade each Qt Version. If you wait too long to upgrade, it can become a bit messy. Also you are helping develop Qt by keeping it active and submitting bugs.

                    Just ported from 5.3.2 to 5.4
                    Only bug I had, some SSL errors now appear on the OS X version in the console ouput..
                    @QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated@
                    Good luck


                    Free Indoor Cycling Software - https://maximumtrainer.com

                    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