How to build Qt¶
The official documentation for building Qt from sources is available at https://doc.qt.io/qt-6/build-sources.html.
Note: These instructions are for building the open-source version of Qt. If you have a commercial license, please use the corresponding binaries using the official Qt Installer.
System Requirements¶
Git >= 1.6.x
CMake >= 3.18.4
Ninja (optional)
A C++ compiler supporting C++17
Perl >= 5.14 (e.g. Strawberry Perl)
Python >= 2.6
Windows: A C++ development environment such as MS Visual Studio >= 2019 or MinGW >= 11.2
Linux: OpenGL development libraries (libgl-dev, libegl-dev, libinput-dev, libfontconfig1-dev )
Getting the Sources¶
Official source code is available at code.qt.io:
cd <source_folder>
git clone https://code.qt.io/qt/qt5.git
Note: Although the URL contains Qt5, the sources also contain the Qt6 code.
Alternatively, the exact source files used to build the current Qat version can be provided: please open an issue on the Qat’s Gitlab project and an archive will be sent to you.
Checkout the version you want to use:
git switch vX.Y.Z
Run the init-repository script to get the submodules:
Linux:¶
./init-repository --module-subset=default,-qtwebengine
Windows:¶
perl .\init-repository --module-subset=default,-qtwebengine
Please refer to Building_Qt_5_from_Git or Building_Qt_6_from_Git for more details.
Setup¶
Windows:¶
Make sure your your compiler and Python executables are found in your PATH environment variable.
Make sure your compiler is before Perl in the PATH variable since Perl comes with version of g++ (8.3) that is not compatible with Qt 5.
Also make sure that Perl is before Git in the PATH variable since Git comes with version of Perl that is not compatible with Qt.
You will also need to add <source_folder>/qtbase/bin, <source_folder>/gnuwin32/bin to the PATH variable.
Configure¶
Create an empty build folder and call the configure script from Qt. it is recommended to create the build folder as a sibling of the source folder.
Windows:¶
Make sure to use a Visual Studio command prompt “x64 Native Tools Command Prompt for VS 20XX”
cd <source_folder>
cd ..
mkdir <build_folder>
cd <build_folder>
../<source_folder>/configure -opensource -confirm-license -nomake examples -nomake tests -release -prefix <install_folder>
Where <install_folder> if the folder where the Qt binaries will be generated. This is the folder the CMAKE_PREFIX_PATH CMake variable should point to when building Qat or any other Qt application.
To select the C++ toolchain, you can pass the additional -platform argument to the configure script. Supported toolchain values are:
Linux:¶
linux-clang
linux-g++
linux-g++-32
Windows:¶
win32-g++
win32-msvc
Build¶
The build process is managed by CMake:
cd <build_folder>
cmake --build . --parallel
cmake --install .
When building Qt 5.X on Windows, the build process is managed by make or mingw32-make:
cd <build_folder>
mingw32-make
mingw32-make install
At this point, Qt should be available in your <install_folder> so you can use it in other applications.