Porting C++ Applications to Qt 6 using Clazy checks
We've implemented some checks and fixits within the Clazy framework to help you port your applications from Qt 5 to Qt 6. In their own words: "Clazy is a compiler plugin which allows clang to understand Qt semantics". Get Clazy (https://invent.kde.org/sdk/clazy) and read on to make porting to Qt 6 smoother.
Clazy checks can be run as a plugin during compilation or over a JSON compilation database using
clazy-standalone. The fixes are applied later, using
The following checks are dedicated to ease the port from Qt 5 to Qt 6.
The checks have to be run against Qt 5. The fixed code is only going to compile against Qt 6. For this reason the above mentioned checks have to be run in one go. Clazy recommends running one test at a time to avoid conflict when applying fixes, but this is not an option when running those checks as a plugin.
How to set up your project to run with Clazy and how to select and apply the checks is fully explained here: https://invent.kde.org/sdk/clazy#setting-up-your-project-to-build-with-clazy.
If you don't want to run the checks as a plugin but rather over a JSON compilation database, you need to use
clazy-standalone. Please see https://invent.kde.org/sdk/clazy#clazy-standalone-and-json-database-support for instructions.
In a nutshell, assuming you have an up to date Clazy version installed, what needs to be done to run the checks as a plugin is explained below.
Set up your project to run with Clazy.
Add the following lines to your qmake command, as appropriate for your OS:
-spec linux-clang QMAKE_CXX="clazy" -spec macx-clang QMAKE_CXX="clazy"
For Windows with MSVC add
--DCMAKE_CXX_COMPILER=clazy to the cmake command.
Select the checks:
export CLAZY_CHECKS="qt6-deprecated-api-fixes, qt6-header-fixes, qt6-qhash-signature, qt6-qlatin1stringchar-to-u, qt6-fwd-fixes"
Enable the fixits:
Set the directories to be ignored by Clazy:
This will prevent Clazy checks from running on the libraries' files. This is necessary if the libraries' paths are included with
-F instead of
-framework. This is also necessary to avoid warnings from
qt-header-fixes check, if the headers triggering the check are included in the included libraries' files.
Compile your code.
.yaml files are created next to the source files.
To apply the fixits, run:
This will modify the source files, consider backing up your code.
Not all porting can be done with automatic fixits. Please look carefully at the warnings during compilation for the code that will have to be changed manually.
© 2021 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.