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, required on MacOS)

  • 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 )

  • MacOS: Xcode with the clang toolchain

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 X.Y.Z

Run the init-repository script to get the submodules:

Linux and MacOS:

./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 only:

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. 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

On MacOS, you can select the target architecture(s) with a CMake variable:

./configure <other arguments> -- -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64"

Note: Intel architecture (“x86_64”) must be specified first, otherwise Qt may not enable all the x86 functionality.

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.