Getting your 3D ready for Qt 6 Compiling Qt 3D for Qt 6 and up
As was previously discussed, since the 6.0.0 release of Qt, Qt 3D no longer ships as a pre-compiled module. If you need to use it on your projects, try out the new features, or just see your existing application is ready for the next chapter of Qt’s life, you need to compile Qt 3D from source.
In order to do this, you can do it the traditional way ([cq]make ...; make; make install) or use the Conan-based system that is being pioneered with the latest version of the MaintenanceTool.
The latest version of the MaintenanceTool (from the unified installers) will optionally install several things:
- Conan, a package manager which can build C++ libraries and handle the dependencies
- CMake, the meta-build system, which is required for Qt 6
- Ninja, the lighting fast replacement for make and nmake
Additionally, you will need to select Qt 3D in the Additional libraries section so that the source code is available.
As mentioned above, these are optional. You need to find them and enable them in the MaintenanceTool’s UI.
Conan, being a package manager, is designed to handle all dependencies to make it easy to build libraries and applications. However, the way this is setup in the current packages installed by the MaintenanceTool is not complete.
Additional things you need for Conan
In particular, you need two other things:
- You need to select the Qt Shader Tools module in the MaintenanceTool, if you intend to use the new RHI-based backend for Qt 3D. Without it, Qt 3D will build fine but only the original (and more feature rich) backend will be available.
- Since Qt 3D is a Qt module, it has many of the similar requirements you need when building Qt itself. At the very least, you need a perl interpreter, so that the module header files can be generated. A full list of requirements for the various platforms is available here.
Once you have all the required bits, it’s time to open a console and run Conan. The process is platform-specific, as each platform has it’s own Conan profile. A complete example is available on the Qt wiki, but this is how it works on my mac where the Qt SDK is installed in /Users/Shared/Qt:
conan install qt3d/6.0.0@qt/final --build=missing -s build_type=Release -g cmake_paths -g=cmake -g deploy --profile=/Users/Shared/Qt/Tools/Conan/profiles/qt-6.0.0-macx-clang
and wait…it takes a while to build Qt 3D.
- conan, cmake and ninja need to be in your path. In particular, make sure the Qt provided version of Conan is found first, because…
- the MaintenanceTool installs a custom version of Conan and write config files in the $HOME/.conan folder. This means, at least on multi-user systems, Conan will only properly work for the user who installed the Qt SDK, and that version is found before any platform-provided version.
Using QMake or CMake
Using the MaintenanceTool and Conan makes it easy to get the source and the required dependencies for building Qt 3D. As we saw in the aforementioned, there are still some rough edges. So, in particular, if you are familiar with building Qt modules already, you can just use the “old way”, i.e., download the source and use QMake, or now, CMake.
The packages for the released versions of Qt 3D (and other Additional modules) are available here.
Once extracted, you can do a shadow build of Qt 3D pretty easily (this has the same build requirements as above though, QtShaderTools module and perl interpreter).
tar zxf qt3d-everywhere-src-6.0.0.tar.xz cd qt3d-everywhere-src-6.0.0 mkdir build cd build /Users/Shared/Qt/6.0.0/clang_64/bin/qmake .. make make install
And, again, wait 🙂.
The process is similar if you want to use CMake instead. In the build folder, do:
/Users/Shared/Qt/6.0.0/clang_64/bin/qt-cmake -G Ninja .. ninja ninja install
Once done, your applications should be able to find the Qt 3D modules.
You can optionally build the documentation using the docs target (but this will not be installed; you will need to register it with Creator and/or QtAssistant for it to appear).
Qt 3D will likely preserve the dual QMake/CMake build system for a while still.
As you see, building Qt 3D involves a bit more work than it did before. Fortunately, it needs to be done only once for each release. Going forward, we will be able to release Qt 3D on a different cycle from the rest of Qt and, as a result, introduce features and bug fixes more frequently. Please do not hesitate to get in touch with us or the Qt build system team if you have questions regarding this new setup.
KDAB provides a number of services around Qt 3D, including mentoring your team and embedding Qt 3D code into your application, among others. You can find out more about these services here.