Building Qt 6.1.0 on Windows 10 With Visual Studio 2019

Time for another short guidance on how to build your own copy of the Qt framework from source.

Qt 6.1.0 was just released, and I thought maybe I should keep in touch with the latest generation, even though I don’t urgently need it right now. On the other hand, I do plan to invest some time into QML/Quick, and for that, I might as well start with the latest version.

From what I picked up over the last months, Qt seem to again as tighten the screws a bit more, regarding licenses and non-commercial support, so the advice from my previous posts, to just get the pre-built binaries via online installer (if you’re not interested in building the framework from soure), maybe doesn’t apply anyomre (don’t know really, don’t care that much). For now; just be aware that The Qt Company is an commercial entity, and just like Microsoft, Google or Apple, they want to make money in the end…

Prerequisites and recommended installation order

  1. Microsoft Visual Studio 2019 (Community Edition) — install it at least with the C++ Desktop workload, the C++ toolset and the Windows SDK.
  2. Perl/ActivePerl — it should be put in PATH for the command prompt build environment after installation.
  3. Python — it should be put in PATH for the command prompt build environment after installation.
    Note that Qt 6 requires a Python 3.x version!
  4. CMake — The framework has switched to CMake for building Qt’s 6th generation, and it requires at least version 3.16 of CMake.

Official page: Qt (6) for Windows - Building from Source.

Download

As usual, I’ll point to the zipped version of the source package; you could also clone it from a Git repository, but I’ll ignore that for now.

The direct way to the source code of version of Qt 6.1.0 is https://download.qt.io/official_releases/qt/6.1/6.1.0/single/qt-everywhere-src-6.1.0.zip, which comes at ca. 377 MB – much lighter than last time’s 800 MByte, but as I understand, Qt 6.1 is also still missing a lot of features and modules…
(There is also a prettier website, but the download link points to the same location as above.)

Extract

Extract it to an appropriate place for you (e.g. I use C:\temp\Qt-6.1.0\ today).
If your extraction tool of choice puts it into sub-directories like qt-everywhere-src-6.1.0, then move the content of it up to the root level and delete this now empty folder(s).

Build

The next steps describe how you build 64-bit DLLs with Visual Studio 2019; for 32-bit files, or static libraries, or…, adjust the paths/names/options accordingly to your needs!

  1. Open the x64 Native Tools Command Prompt for VS 2019 (you can find it in the start menu entry ‘Visual Studio 2019’) and navigate to C:\temp\Qt-6.1.0\ (or whatever your chosen location is…).

  2. Run Qt’s configure.bat from there to prepare the build – but first, make some choices:

    The following list of options is a setup that works for me, for my current projects; you may need different features enabled/disabled, etc.
    Run configure -h to get the full list of options.

    Argument Comment
    -prefix <DIR> The installation destination directory.
    <DIR> should be a full path like “C:\devel\shared\Qt-6.1.0-x64”
    -release Release-only build (Build Qt with debugging turned off).
    -shared Build shared libraries (i.e. DLLs).
    -make tools Build also tools like lupdate/linguist/lrelease and so on.
    -nomake examples Exclude examples.
    -nomake tests Exclude tests.

    That means, you’ll execute a long command, like:

     C:\temp\Qt-6.1.0\> configure.bat -prefix C:\devel\shared\Qt-6.1.0-x64 -release -shared ...
    
    • By the way: The first attempt stopped immediately for me with an error:
      The message indicated that it had issues finding Ninja, and previous values in CMake’s cache wouldn’t match with the just now created configuration.
      Well, I didn’t have/use Ninja, nor did I ever try to do a build of Qt 6 with CMake before this one.

      Luckily, the tip in that message also helped: After deleting the file C:\temp\Qt-6.1.0\CMakeCache.txt and trying again, it worked.
      (This file shouldn’t have been there in the zip file for deployment…)

  3. Type cmake --build . --parallel to kick-off the building process.
    Mind the dot after “–build”! That means that the current directory [meaning C:\temp\Qt-6.1.0\] will be also the build directory.

    This may take quite a while, depending on your equipment (in my case a few hours).
    To clean up (e.g. after a failed build, before trying again), delete the file CMakeCache.txt (as already mentioned above) and configure again/new; then build this again.

  4. Finally, run cmake --install .
    Again: Mind the trailing dot! This line translates to: “Install the sources from the current directory [meaning C:\temp\Qt-6.1.0\] to the destination directory that was specified during the configuration step with the -prefix parameter.

That’s all, folks!