Porting from Qt 4 to 5
By Jeff Tranter | Wednesday, February 3, 2016
Looking for a New Year's resolution for 2016?
Official support for Qt version 4 came to an end in December 2015. Qt version 5 first came out in 2013 and is currently at version 5.5.1, with the 5.6.0 release coming early this year. Qt 5.6.0 will be the first LTS (Long Term Support) release, with a commitment to be supported for three years.
If you are still using Qt 4, it really is time to start thinking about migrating your code to Qt 5.
In a previous blog post (1), written almost exactly three years ago, I discussed my experiences porting about 14,000 lines of Qt widget-based application code in only a few hours. The source code was for the examples from the book C++ GUI Programming with Qt 4 by Jasmin Blanchette and Mark Summerfield.
That code covered a wide range of Qt's APIs and was quite simple to port to Qt 5. While Qt 5 is not binary compatible with Qt 4, it is mostly source compatible. A general rule of thumb is that Qt 5 is about 99% source compatible with Qt 4.
Qt 5 offers a number of advantages over Qt 4, most notably support for new platforms and development tools and many new classes and features for existing classes. If you are using Qt Quick (QML), the new Qt Quick 2 introduced in Qt 5 offers significant new functionality and makes use of OpenGL support.
That said, there may be situations where you don't want to port to Qt 5. This could include desktop applications that you never plan to update or make fixes to, or if you are tied to a very old compiler that is no longer supported under Qt 5. If your code makes extensive use of deprecated or removed classes like QFtp or Qt3Support you might also not want to ever port it to Qt 5. But in the vast majority of cases it makes sense to port to Qt 5.
There is a wealth of information available on Qt 4 to 5 porting, some of which I've listed here under References. So why not make it a resolution for 2016 to move all your applications over to Qt 5?
- Porting Desktop Applications from Qt 4 to Qt 5, ICS blog post, accessed 5 Jan 2016, www.ics.com/blog/porting-desktop-applications-qt-4-qt-5
- What's New in Qt 5.0, Qt documentation, accessed 5 Jan 2016, doc.qt.io/qt-5/whatsnew50.html
- What's New in Qt 5, Qt documentation, accessed 5 Jan 2016, doc.qt.io/qt-5/qt5-intro.html
- Porting Guide, Qt documentation, accessed 5 Jan 2016, doc.qt.io/qt-5/portingguide.html
- Porting C++ Applications to Qt 5, Qt documentation, accessed 5 Jan 2016, doc.qt.io/qt-5/portingcppapp.html
- Porting QML Applications to Qt 5 Example, Qt documentation, accessed 5 Jan 2016, doc.qt.io/qt-5/portingqmlapp.html
- Porting QML Applications to Qt 5, Qt documentation, accessed 5 Jan 2016, doc.qt.io/qt-5/qtquick-porting-qt5.html
- Transition from Qt 4.x to Qt 5, Qt Wiki page, accessed 5 Jan 2016, wiki.qt.io/Transition_from_Qt_4.x_to_Qt5