How to build Qt6 from source on Windows?

Download and install software required to build Qt6 with VS

To build Qt6 on Windows using Visual Studio, you need to install several software:

Note that the minimum Visual Studio version that supports building Qt 6 is VS version 16.7 (VC++ version 14.27). So you need to install at least Visual Studio 2019 to build Qt6 from source. Visual Studio 2017 does not support Qt6 and you will get the error:

fatal error C1189: #error:  “Qt requires at least Visual Studio 2019 version 16.7 (VC++ version 14.27). Please upgrade.”
ninja: build stopped: subcommand failed.

Environment variables to set to build Qt6 on Windows

make sure the paths that contain python.exe, perl.exe, ninja.exe, cmake.exe are included in the PATH environment variable. The paths are like:

  • C:\Python\Python310
  • C:\Strawberry\perl\bin
  • C:\ninja
  • C:\CMake\bin

Create cmd shortcut with VS environment

We have talked about how to create a cmd shortcut with proper environment variables set up. The .cmd file you will create contains the following content:

CALL "C:\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
SET _ROOT=C:\qt-everywhere-src-6.4.1
SET PATH=%_ROOT%\qtbase\bin;%PATH%
SET _ROOT=

Configure and build Qt6 from source

Click the cmd shortcut you created in previous step to run a cmd window, where you compile Qt6 from source. Create a directory for shadow build such as C:\qtbuild, cd to that directory to run the following commands:

C:\qt-everywhere-src-6\configure.bat -prefix C:\Qt6  -debug-and-release  -platform win32-msvc -opensource -confirm-license  -openssl-runtime -- -DOPENSSL_ROOT_DIR=C:\openssl

cmake --build . --parallel
ninja install

The first command is to configure Qt to support SSL. The second command is to build Qt6 with cmake. The third command is to install built Qt to target directory. C:\qt-everywhere-src-6 is where the Qt6 source is put. –prefix is where the built Qt6 will be installed. C:\openssl is where openssl is installed. Make sure the openssl is also built with Microsoft Visual Studio and is 64bit, otherwise, configure will fail with the following error:

CMake Error at qtbase/cmake/QtBuildInformation.cmake:490 (message):
Feature “openssl”: Forcing to “ON” breaks its condition:

QT_FEATURE_openssl_runtime OR QT_FEATURE_openssl_linked

Condition values dump:

QT_FEATURE_openssl_runtime = “OFF”
QT_FEATURE_openssl_linked = “OFF”

Posted in

Leave a Reply