Migrating from Qt 5 to Qt 6

Bryan Cairns (VoidRealms)
6 min readFeb 24, 2021

I have always had a love hate relationship with version changes. On one hand I really want to use all the shiny new features and APIs, but on the other hand I dread….and I mean DREAD seeing working code that has been working for years suddenly need to be re-written.

Qt 6 released

When Qt 6 was released, I probably set a world speed record for how fast I opened a browser to read about it.

When creating Qt 6, we ensured that Qt’s core values have been adhered to and upheld, including:

Its cross-platform nature, allowing users to deploy their applications to all desktop, mobile, and embedded platforms using one technology and from a single codebase

Its scalability from low-end, single-purpose devices to high-end complex desktop applications or connected system

Its world-class APIs and tools and documentation, simplifying the creation of applications and devices

Its maintainability, stability, and compatibility, allowing users to maintain large codebases with minimal effort

Its large developer ecosystem with more than 1.5 million users

Qt 6.0 is the first release of the Qt 6 series addressing new market demands while keeping the core values at the heart of what we do.

When developing Qt 6, we had an in-depth look at some of Qt’s most central parts to identify how we could improve them. We discovered a couple of core focus areas that we invested considerable time in improving. Those areas include:

Leveraging C++17

Next generation QML

New graphics architecture

Unified 2D and 3D for Qt Quick

CMake build system (with qmake still supported for applications)

That one line really stood out: “maintainability, stability, and compatibility, allowing users to maintain large codebases with minimal effort”

We hear this promise a lot from vendors and I always mock it, because as developers…we know how it will really be...we know…

Downloading…installing…failing…

Completely disregarding to read any real documentation, I cracked open the maintenance tool and downloaded Qt 6, along with the source, and noticed a “ Qt 5 Core Compat module” — sure why not, add it to the download.

The installer issued an error message…sadly my linux box was too old to run the newest version of Qt — I was faced with some hard choices…upgrade to a newer version of Linux or build from source.

Building from source

To be fair, I did not read the manual…actually I did not read any instructions, as a user I simply expected it to “just work” — but as developers we know…we know.

In Qt’s defense — I have been, and still am; on an unsupported version of Linux, an older Mac book pro, and a Windows box that honestly, is so old that I am surprised even runs every time I press the power button.

Determined to get this working, I compiled from source, both dynamically and statically.

After building, most things right out of the box “just worked” — but I wanted to really see how much of Qt changed.

Setting up a virtual machine

I wanted to make sure I got the right experience with Qt, and when I record tutorials for YouTube and Udemy, I wanted to make sure I did not have weird bugs due to my OS being out dated. The problem switching to a newer version also means installing all my applications and settings over again — they always say the upgrade will be painless but in the end we always end up doing a fresh install — as developers we know…we know…

Testing hundreds of Qt applications

You may or may not know, I have worked with Qt for a really long time. Having written literally thousands of apps in all shapes and sizes ranging from hello world to multi-threaded TCP apps that are distributed across a virtual network of nodes working together to crunch numbers.

To say I had a lot of code to test was an understatement.

So I did what any lazy developer would do — I automated it.

Using python scripts to setup the code, convert it to CMake, convert it to Qt6 and recompile each application with both QMake and CMake, I was able to test hundreds of apps in varying complexity over a week.

Qt 5 Compatibility?

The main thing I found was — most things “just worked”!

The things that did not “just work” usually involved:

QByteArray — had to explicitly cast data into it rather than trusting it to be implicitly cast for me.

QString — Some monitor changes, seems they really re-worked this class.

QTcpSocket — They moved the SocketError signal (finally!!!) to errorOccured making it easier.

QDateTime — they did away with some of the more confusing aspects of this.

Widgets — a few minor things, but nothing I could not figure out. Wow they are still maintaining widgets, this is awesome, I have long feared they will drop support in favor of QML. But I LOVE widgets.

QML — The only major show stopper for me was menus, they simply don’t work on my Cinnamon desktop (Linux Mint).

A few other minor things — but as promised — Qt made things “just work”.

For the thing that did not “just work”, they includes the Qt 5 Core Compat module. Adding it to a project was super easy:

Qt 5 Core Compatibility APIs: https://doc.qt.io/qt-6/qtcore5-index.html

For QMake:

QT += core5compat

For CMake

find_package(Qt6 COMPONENTS Core5Compat REQUIRED)
target_link_libraries(mytarget PUBLIC Qt6::Core5Compat)

After adding that — (and making sure to use it correctly) — most stubborn code just started working again.

Bravo Qt…Bravo! I am beyond words

Learning from Experience

From all of this, I was able to condense this journey into a 3+ hour course that walks through 20 projects and really highlights the issues you will face, and how to over come them. Here is a preview:

If you are interested the course is available on Udemy and has been getting good reviews, we are all in the VoidRealms facebook group looking at various migration issues:

Migrating to Qt 6
https://www.udemy.com/course/migrating-to-qt-6/?referralCode=F4775D810BD9551083B6

Re-Recording for Qt 6

I will be re-recording all my Qt5 content on YouTube and Udemy for Qt 6. If you are interested here are the links — please note I am in the process of recording these over again for Qt 6 which was just released, current students of the Qt 5 courses will get the Qt 6 courses for free.

Qt 5 Core for beginners with C++
https://www.udemy.com/course/qt-core-for-beginners/?referralCode=E2115FC6B3CC3BD742AF

Qt 5 Core Intermediate with C++
https://www.udemy.com/course/qt-core-intermediate/?referralCode=1F1A60AF279FEE1719CD

Qt 5 Core Advanced with C++
https://www.udemy.com/course/qt-core-advanced/?referralCode=8DB432110F38B253D251

Qt 5 Widgets for beginners with C++
https://www.udemy.com/course/qt-widgets-beginners/?referralCode=1B2FA9787D88D97D38D3

QML for beginners with Qt 5
https://www.udemy.com/course/qml-for-beginners/?referralCode=3B69B9927B587BBF40F1

Qt 5 Design Patterns
https://www.udemy.com/course/qt-5-design-patterns/?referralCode=3C2C41D87AB3A17B395F

Migrating to Qt 6
https://www.udemy.com/course/migrating-to-qt-6/?referralCode=F4775D810BD9551083B6

Awarded Content Creator in the 2020 Qt Champion Awards:

“Bryan has a few courses available on Udemy, specifically his course on Qt 5 Design Patterns and also has a popular group on Facebook which helps others with their Qt questions as well. For his work alone in creating the Qt 5 training course online for everyone to benefit from it was easy to make him our year’s Content Creator.”

Follow me on:

YouTube: https://www.youtube.com/user/VoidRealms

Facebook: https://www.facebook.com/groups/1400884323467285

Udemy: https://www.udemy.com/user/bryan-cairns/

--

--