Qt for Windows - Building from Source
Qt for Windows-从源代码构建
This page describes the process of configuring and building Qt for Windows. To download and install a pre-built Qt for Windows, follow the instructions on the Getting Started with Qt page.
此页面描述了为Windows配置和构建Qt的过程。要下载并安装适用于Windows的预构建Qt,请按照Qt入门页面上的说明进行操作。
Step 1: Getting the Sources
第一步:获取源码
Qt sources can be installed in Qt Online Installer. Source packages are also available through Git, as archives in the Qt Account (commercial users), and on download.qt.io (open-source users).
Qt源代码可以安装在Qt Online Installer中。源代码包也可以通过Git获得,作为Qt帐户(商业用户)和download.Qt.io(开源用户)中的存档。
If you install the sources through Qt Online Installer, they will be available in the Qt installation directory, for instance C:\Qt\6.8.1\Src
.
如果通过Qt Online Installer安装源代码,它们将在Qt安装目录中可用,例如C:\Qt\6.8.1\Src。
If you downloaded the source archive, extract it to a directory of your choice, for instance C:\dev\Qt\src
.
如果下载了源代码存档,请将其解压缩到选择的目录中,例如C:\dev\Qt\src。
Note: The path to the source directory must not contain any spaces or Windows-specific file system characters. The path should also be kept short. This prevents issues with too long file paths in the compilation phase.
注意:源目录的路径不得包含任何空格或Windows特定的文件系统字符。这条路也应该保持短。这可以防止在编译阶段出现文件路径过长的问题。
Step 2: Installing Build Requirements and Set Environment
步骤2:安装构建要求和设置环境
To build Qt from sources you need a build environment with a supported compiler and various build tools.
要从源代码构建Qt,需要一个具有受支持的编译器和各种构建工具的构建环境。
Build Tools
构建工具
Tool | Supported Versions | Description |
---|---|---|
CMake | Version 3.16 and newer (3.17 and newer for 3.16及更新版本(3.17及更新版本用于 | Required for configuring the Qt build. Available in Qt Online Installer and on cmake.org. 配置Qt构建所必需的。可在Qt在线安装程序和cmake.org上使用。 |
Ninja | - | Recommended tool for building Qt. Available in Qt Online Installer and on ninja-build.org. 构建Qt的推荐工具。可在Qt在线安装程序和ninja-build.org上找到。 |
Python | Version 3 | Required build tool. Windows installers are available on python.org, or from the Microsoft Store. |
The executables cmake.exe
, ninja.exe
, and python.exe
must be available in your build environment. Add the respective directory to your PATH
environment variable.
可执行文件cmake.exe、ninja.exe和python.exe必须在构建环境中可用。将相应的目录添加到PATH环境变量中。
Compilers
编译器
The following compilers and configurations are supported in Qt 6.8:
Qt 6.8支持以下编译器和配置:
Operating System | Architecture | Compiler | Notes |
---|---|---|---|
Windows 10 (1809 or later) | x86_64 | MSVC 2022, MSVC 2019, Mingw-w64 13.1 | |
Windows 11 | x86_64 | MSVC 2022, MSVC 2019, Mingw-w64 13.1 | |
Windows on ARM | arm64 | MSVC 2019/2022 | Technology Preview |
Note: Windows on ARM is only supported as a deployment target. Applications have to be cross-compiled from an x86-64 Windows machine and deployed to target.
注意:ARM上的Windows仅支持作为部署目标。应用程序必须从x86-64 Windows计算机交叉编译并部署到目标。
QDoc Dependencies
QDoc依赖关系
QDoc uses Clang to parse C++ code. If you wish to build QDoc manually, refer to Installing Clang for QDoc for specific build requirements.
QDoc使用Clang来解析C++代码。如果希望手动构建QDoc,请参阅安装用于QDoc的Clang以了解具体的构建要求。
Qt GRPC and Qt Protobuf Dependencies
Qt GRPC和Qt Protobuf依赖关系
Qt GRPC and Qt Protobuf require installing gRPC
and Protobuf
packages. You can find the installation instructions for the packages in the Example of installation for Windows using vcpkg.
Qt GRPC和Qt Protobuf需要安装GRPC和Protobuf软件包。可以在使用vcpkg安装Windows的示例中找到软件包的安装说明。
Setting the Environment
设置环境
For MSVC, do one of the following:
对于MSVC,请执行以下操作之一:
- Run the vcvarsall.bat:
运行vcvarsall.bat:"C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\Build\vcvarsall.bat" amd64
- Search on the Windows search bar for the VS Native Tools command prompt.
- 在Windows搜索栏上搜索VS本机工具命令提示符。
For Mingw-w64: Add Mingw-w64 to PATH
environment variable:
对于Mingw-w64:将Mingw-w64添加到PATH环境变量中:
Set PATH=C:\qt\tools\mingw1120_64\bin;%PATH%
Step 3: Building the Qt Libraries and Tools
步骤3:构建Qt库和工具
To configure your build, create a build directory and run the configure.bat
script in this directory:
要配置构建,请创建一个构建目录,并在此目录中运行configure.bat脚本:
mkdir C:\dev\qt-build
cd C:\dev\qt-build
C:\dev\Qt\src\configure.bat
By default, Qt is configured for installation in the C:\Qt\Qt-major.minor.patch
directory, where the major.minor.patch triplet represents the Qt version being built. This can be changed by using the -prefix
option. See the list of Qt Configure Options to tweak further.
默认情况下,Qt配置为安装在C:\Qt\Qt-major.minor.patch目录中,其中major.minior.patch三元组表示正在构建的Qt版本。这可以通过使用-prefix选项来更改。请参阅Qt配置选项列表以进行进一步调整。
Then build the libraries and tools:
然后构建库和工具:
cmake --build . --parallel
Period after --build
means current folder.
--build后的句点表示当前文件夹。
After building, you need to install the libraries and tools in the desired path (unless you enabled a developer build:
构建后,需要在所需的路径中安装库和工具(除非启用了开发人员构建:
cmake --install .
Step 4: Building Your Application
步骤4:构建应用程序
After Qt is installed, you can start building applications with it.
安装Qt后,可以开始使用它构建应用程序。
If you work from the command line, consider adding the Qt tools to your PATH
environment variable as follows:
如果从命令行工作,请考虑将Qt工具添加到PATH环境变量中,如下所示:
set PATH=C:\Qt\Qt-major.minor.patch\bin;%PATH%
If you plan to use Qt from an IDE, you need to register the Qt version explicitly there. For Qt Creator, see Qt Creator: Adding Qt Versions.
如果你打算在IDE中使用Qt,需要在那里明确注册Qt版本。对于Qt Creator,请参阅Qt Creator:添加Qt版本。
© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.