赞
踩
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入门”页面上的说明进行操作。
Qt sources can be installed in the Qt Online Installer. Source packages are also available as Git repositories, as archives in the Qt Account (commercial users), and on download.qt.io (open-source users).
Qt源可以安装在Qt在线安装程序中。源码包也可作为存档在(商业用户)和(开源用户)中提供。
If you install the sources through the Qt Online Installer, they will be available in the Qt installation directory, for instance C:\Qt\6.5.3\Src
.
如果您通过Qt在线安装程序安装源代码,它们将在Qt安装目录中可用,例如。C:\Qt\6.5.3\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 avoids issues with too long file paths in the compilation phase.
注意: 源目录的路径不得包含任何空格或特定于 Windows 的文件系统字符。路径也应保持简短。这样可以避免在编译阶段出现文件路径过长的问题。
To build Qt from sources you need a build environment with a supported compiler and various build tools available:
要从源代码构建Qt,您需要一个具有支持的编译器和各种可用构建工具的构建环境:
Tool | Supported Versions | Description |
---|---|---|
CMake | Version 3.16 and newer (3.17 and newer for -debug-and-release builds 3.21 and newer for -static builds). | Required for configuring the Qt build. Available in the Qt Online Installer and on cmake.org. |
Ninja | - | Recommended tool for building Qt. Available in the Qt Online Installer and on 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. You achieve this by adding the respective directory to your PATH
environment variable.
The following compilers and configurations are supported in Qt 6.5:
Qt 6.5支持以下编译器和配置:
Operating System | Architecture | Compiler |
---|---|---|
Windows 10 (1809 or later) | x86_64 | MSVC 2022, MSVC 2019, MinGW 11.2 |
Windows 11 | x86_64 | MSVC 2022, MSVC 2019, MinGW 11.2 |
Windows on ARM | arm64 | MSVC 2019/2022 |
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 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,请参阅Installing Clang for QDoc以了解特定的构建需求。
We recommend creating a desktop link that opens a command prompt with the environment set up similar to the Command Prompt menu entries provided by Visual Studio. This is done by creating an application link passing a .cmd
file setting up the environment and the command line option /k
(remain open) to cmd.exe
.
我们建议创建一个桌面链接,该链接打开命令提示符,其环境设置类似于 Visual Studio 提供的菜单项。这是通过创建一个应用程序链接来完成的,该链接将设置环境和命令行选项(保持打开状态)的文件传递给cmd 。
Assuming the file is called qt6vars.cmd
and the Qt folder is called C:\Qt\6.5.3\Src
:
假设文件被调用并且Qt文件夹被调用:qt6vars.cmdC:\Qt\6.5.3\Src
REM Set up compiler, in this case Visual Studio Professional 2022 for amd64 CPU's
CALL "C:\\Program Files\\Microsoft Visual Studio\\2022\\Professional\\VC\\Auxiliary\\Build\\vcvarsall.bat" amd64
SET _ROOT=C:\\Qt\\6.5.3\\Src
SET PATH=%\_ROOT%;%PATH%
SET _ROOT=
A desktop link can then be created by specifying the command %SystemRoot%\system32\cmd.exe /E:ON /V:ON /k C:\Qt\qt6vars.cmd
as application.
然后,可以通过将命令指定为应用程序来创建桌面链接。
Depending on your individual setup, you might also need to make the installation directories of CMake, Ninja, and Python part of the SET %PATH%
line above.
根据您的个人设置,您可能还需要将 CMake、Ninja 和 Python 的安装目录作为上述行的一部分。SET %PATH%
Note: Setups for MinGW are similar; they differ only in that the bin
folder of the installation should be added to the path instead of calling the Visual Studio setup script. For MinGW, please make sure that no sh.exe
can be found in the path, as it affects mingw32-make
.
注意: MinGW的设置类似;它们的区别仅在于应将安装文件夹添加到路径中,而不是调用 Visual Studio 安装脚本。对于 MinGW,请确保在路径中找不到 no,因为它会影响 。
To configure the Qt library for your machine type, create a build directory and change to this directory. Then call the configure.bat
script. Alternatively, if you have already completed Step 3, you may double-click on the desktop link you created, change to the build directory, type configure
and start configuring the Qt library.
要为您的机器类型配置 Qt 库,请创建一个构建目录并切换到此目录。然后调用脚本。或者,如果您已经完成了步骤3,则可以双击您创建的桌面链接,切换到构建目录,键入并开始配置Qt库。configure.batconfigure
Note: Add the Qt build directory to the list of excluded directories of any anti-virus application that runs on your system.
注意: 将Qt构建目录添加到系统上运行的任何防病毒应用程序的排除目录列表中。
mkdir qt6-build
cd qt6-build
C:\\Qt\\6.5.3\\Src\\configure.bat
cmake --build .
cmake --install .
By default, Qt is configured for installation in the C:\Program Files\Qt
directory, but this can be changed by using the -prefix
option.
默认情况下,Qt 配置为在目录中安装,但可以使用该选项-prefix
进行更改。
The Configure Options page contains more information about the configure options. See Qt for Windows - Graphics Acceleration for specific options regarding graphics acceleration.
该页面包含有关配置选项的详细信息。有关图形加速的特定选项,请参阅。
Qt 配置选项运行$ ./qt62/configure --help > ./123.txt
可以查看配置选项。
Usage: configure [options] [-- cmake-options] This is a convenience script for configuring Qt with CMake. Options after the double dash are directly passed to CMake. Top-level installation directories: -prefix <dir> ...... The deployment directory, as seen on the target device. [/usr/local/Qt-$QT_VERSION; qtbase build directory if -developer-build] -no-prefix ......... The deployment directory is set to the qtbase build directory. Can be used instead of -developer-build to not have to install, as well as avoid -developer-build's default of -warnings-are-errors. -extprefix <dir> ... The installation directory, as seen on the host machine. [SYSROOT/PREFIX] Fine tuning of installation directory layout. Note that all directories except -sysconfdir should be located under -prefix: -bindir <dir> ......... Executables [PREFIX/bin] -headerdir <dir> ...... Header files [PREFIX/include] -libdir <dir> ......... Libraries [PREFIX/lib] -archdatadir <dir> .... Arch-dependent data [PREFIX] -plugindir <dir> ...... Plugins [ARCHDATADIR/plugins] -libexecdir <dir> ..... Helper programs [ARCHDATADIR/bin on Windows, ARCHDATADIR/libexec otherwise] -qmldir <dir> ......... QML imports [ARCHDATADIR/qml] -datadir <dir> ........ Arch-independent data [PREFIX] -docdir <dir> ......... Documentation [DATADIR/doc] -translationdir <dir> . Translations [DATADIR/translations] -sysconfdir <dir> ..... Settings used by Qt programs [PREFIX/etc/xdg] -examplesdir <dir> .... Examples [PREFIX/examples] -testsdir <dir> ....... Tests [PREFIX/tests] -hostdatadir <dir> .... Data used by qmake [PREFIX] Conventions for the remaining options: When an option's description is followed by a list of values in brackets, the interpretation is as follows: 'yes' represents the bare option; all other values are possible prefixes to the option, e.g., -no-gui. Alternatively, the value can be assigned, e.g., --gui=yes. Values are listed in the order they are tried if not specified; 'auto' is a shorthand for 'yes/no'. Solitary 'yes' and 'no' represent binary options without auto-detection. Configure meta: -help, -h ............ Display this help screen -redo ................ Re-configure with previously used options. Additional options may be passed, but will not be saved for later use by -redo. -feature-<feature> ... Enable <feature> -no-feature-<feature> Disable <feature> [none] -list-features ....... List available features. Note that some features have dedicated command line options as well. Build options: -cmake-generator <name> ... Explicitly specify the build system generator for CMake instead of auto-detecting one. -cmake-use-default-generator ... Turn off auto-detection of the CMake build system generator. -cmake-file-api ...... Let CMake store build metadata for loading the build into an IDE. [no; yes if -developer-build] -no-guess-compiler ... Do not guess the compiler from the target mkspec. -release ............. Build Qt with debugging turned off [yes] -debug ............... Build Qt with debugging turned on [no] -debug-and-release ... Build two versions of Qt, with and without debugging turned on [yes] (Apple and Windows only) -optimize-debug ...... Enable debug-friendly optimizations in debug builds [auto] (Not supported with MSVC or Clang toolchains) -optimize-size ....... Optimize release builds for size instead of speed [no] -force-debug-info .... Create symbol files for release builds [no] -separate-debug-info . Split off debug information to separate files [no] -gdb-index ........... Index the debug info to speed up GDB [no; auto if -developer-build with debug info] -gc-binaries ......... Place each function or data item into its own section and enable linker garbage collection of unused sections. [auto for static builds, otherwise no] -force-asserts ....... Enable Q_ASSERT even in release builds [no] -developer-build ..... Compile and link Qt for developing Qt itself (exports for auto-tests, extra checks, etc.) [no] -shared .............. Build shared Qt libraries [yes] (no for UIKit) -static .............. Build static Qt libraries [no] (yes for UIKit) -framework ........... Build Qt framework bundles [yes] (Apple only) -platform <target> ... Select mkspec for the qmake companion files -device <name> ....... Select devices/mkspec for the qmake companion files -device-option <key=value> ... Add option for the device mkspec -appstore-compliant .. Disable code that is not allowed in platform app stores. This is on by default for platforms which require distribution through an app store by default, in particular Android, iOS, tvOS, and watchOS. [auto] -qt-host-path <path> . Specify path to a Qt host build for cross-compiling. -qtnamespace <name> .. Wrap all Qt library code in 'namespace <name> {...}'. -qtlibinfix <infix> .. Rename all libQt6*.so to libQt6*<infix>.so. -testcocoon .......... Instrument with the TestCocoon code coverage tool [no] -gcov ................ Instrument with the GCov code coverage tool [no] -trace [backend] ..... Enable instrumentation with tracepoints. Currently supported backends are 'etw' (Windows) and 'lttng' (Linux), or 'yes' for auto-detection. [no] -sanitize {address|thread|memory|fuzzer-no-link|undefined} Instrument with the specified compiler sanitizer. Note that some sanitizers cannot be combined; for example, -sanitize address cannot be combined with -sanitize thread. -c++std <edition> .... Select C++ standard <edition> [c++20/c++17/c++14/c++11] -sse2 ................ Use SSE2 instructions [auto] -sse3/-ssse3/-sse4.1/-sse4.2/-avx/-avx2/-avx512 Enable use of particular x86 instructions [auto] Enabled ones are still subject to runtime detection. -mips_dsp/-mips_dspr2 Use MIPS DSP/rev2 instructions [auto] -qreal <type> ........ typedef qreal to the specified type. [double] Note: this affects binary compatibility. -R <string> .......... Add an explicit runtime library path to the Qt libraries. Supports paths relative to LIBDIR. -rpath ............... Link Qt libraries and executables using the library install path as a runtime library path. Similar to -R LIBDIR. On Apple platforms, disabling this implies using absolute install names (based in LIBDIR) for dynamic libraries and frameworks. [auto] -reduce-exports ...... Reduce amount of exported symbols [auto] -reduce-relocations .. Reduce amount of relocations [auto] (Unix only) -plugin-manifests .... Embed manifests into plugins [no] (Windows only) -static-runtime ...... With -static, use static runtime [no] (Windows only) -pch ................. Use precompiled headers [auto] -ltcg ................ Use Link Time Code Generation [no] -linker [bfd,gold,lld] Force use of the GNU ld, GNU gold or LLVM/LLD linker instead of default one (GCC only) -ccache .............. Use the ccache compiler cache [no] (Unix only) -warnings-are-errors . Treat warnings as errors [no; yes if -developer-build] Build environment: -sysroot <dir> ....... Set <dir> as the target sysroot -pkg-config .......... Use pkg-config [auto] (Unix only) -D <string> .......... Pass additional preprocessor define -I <string> .......... Pass additional include path -L <string> .......... Pass additional library path -F <string> .......... Pass additional framework path (Apple only) -sdk <sdk> ........... Build Qt using Apple provided SDK <sdk>. The argument should be one of the available SDKs as listed by 'xcodebuild -showsdks'. -android-sdk path .... Set Android SDK root path [$ANDROID_SDK_ROOT] -android-ndk path .... Set Android NDK root path [$ANDROID_NDK_ROOT] -android-ndk-platform Set Android platform -android-abis ....... Only one ABI can be specified, default is: armeabi-v7a -android-javac-target Set the javac build target version [8] -android-javac-source Set the javac build source version [8] -android-style-assets Automatically extract style assets from the device at run time. This option makes the Android style behave correctly, but also makes the Android platform plugin incompatible with the LGPL2.1. [yes] Component selection: -submodules <repo>[,<repo>] ... Build the listed repositories and those they depend on rather than all checked-out repositories. The list should be separated with commas, e.g. -submodules qtsvg,qtnetworkauth [default is to build all checked out repositories] -skip <repo>[,<repo>] Exclude one or more entire repositories from the build. The list should be separated with commas. e.g. -skip qtimageformats,qtsvg -make <part> ......... Add <part> to the list of parts to be built. Specifying this option clears the default list first. (allowed values: libs, tools, examples, tests, benchmarks, manual-tests, minimal-static-tests) [default: libs and examples, also tools if not cross-building, also tests if -developer-build] -nomake <part> ....... Exclude <part> from the list of parts to be built. -gui ................. Build the Qt GUI module and dependencies [yes] -widgets ............. Build the Qt Widgets module and dependencies [yes] -no-dbus ............. Do not build the Qt D-Bus module [default on Android and Windows] -dbus-linked ......... Build Qt D-Bus and link to libdbus-1 [auto] -dbus-runtime ........ Build Qt D-Bus and dynamically load libdbus-1 [no] -accessibility ....... Enable accessibility support [yes] Note: Disabling accessibility is not recommended. Qt comes with bundled copies of some 3rd party libraries. These are used by default if auto-detection of the respective system library fails. Core options: -doubleconversion .... Select used double conversion library [system/qt/no] No implies use of sscanf_l and snprintf_l (imprecise). -glib ................ Enable Glib support [no; auto on Unix] -eventfd ............. Enable eventfd support -inotify ............. Enable inotify support -icu ................. Enable ICU support [auto] -pcre ................ Select used libpcre2 [system/qt/no] -zlib ................ Select used zlib [system/qt] Logging backends: -journald .......... Enable journald support [no] (Unix only) -syslog ............ Enable syslog support [no] (Unix only) -slog2 ............. Enable slog2 support [auto] (QNX only) Network options: -ssl ................. Enable either SSL support method [auto] -no-openssl .......... Do not use OpenSSL [default on Apple] -openssl-linked ...... Use OpenSSL and link to libssl [no] -openssl-runtime ..... Use OpenSSL and dynamically load libssl [auto] -schannel ............ Use Secure Channel [auto] (Windows only) -securetransport ..... Use SecureTransport [auto] (Apple only) -sctp ................ Enable SCTP support [no] -libproxy ............ Enable use of libproxy [no] -system-proxies ...... Use system network proxies by default [yes] Gui, printing, widget options: -cups ................ Enable CUPS support [auto] (Unix only) -fontconfig .......... Enable Fontconfig support [auto] (Unix only) -freetype ............ Select used FreeType [system/qt/no] -harfbuzz ............ Select used HarfBuzz-NG [system/qt/no] (Not auto-detected on Apple and Windows) -gtk ................. Enable GTK platform theme support [auto] -no-opengl ........... Disable OpenGL support -opengl <api> ........ Enable OpenGL support. Supported APIs: es2, desktop (default on Unix), dynamic (Windows only, default on Windows) -opengles3 ........... Enable OpenGL ES 3.x support instead of ES 2.x [auto] -egl ................. Enable EGL support [auto] -qpa <name> .......... Select default QPA backend(s) (e.g., xcb, cocoa, windows) A prioritized list separated by semi-colons. -xcb-xlib............. Enable Xcb-Xlib support [auto] Platform backends: -direct2d .......... Enable Direct2D support [auto] (Windows only) -directfb .......... Enable DirectFB support [no] (Unix only) -eglfs ............. Enable EGLFS support [auto; no on Android and Windows] -gbm ............... Enable backends for GBM [auto] (Linux only) -kms ............... Enable backends for KMS [auto] (Linux only) -linuxfb ........... Enable Linux Framebuffer support [auto] (Linux only) -xcb ............... Enable X11 support [auto] (Linux only) Input backends: -libudev............ Enable udev support [auto] -evdev ............. Enable evdev support [auto] -libinput .......... Enable libinput support [auto] -mtdev ............. Enable mtdev support [auto] -tslib ............. Enable tslib support [auto] -bundled-xcb-xinput Use bundled XInput2 support [auto] -xkbcommon ......... Enable key mapping support [auto] Image formats: -gif ............... Enable reading support for GIF [auto] -ico ............... Enable support for ICO [yes] -libpng ............ Select used libpng [system/qt/no] -libjpeg ........... Select used libjpeg [system/qt/no] Database options: -sql-<driver> ........ Enable SQL <driver> plugin. Supported drivers: db2 ibase mysql oci odbc psql sqlite [all auto] -sqlite .............. Select used sqlite [system/qt] Qt3D options: -assimp .............. Select used assimp library [system/qt/no] -qt3d-profile-jobs ... Enable jobs profiling [no] -qt3d-profile-gl ..... Enable OpenGL profiling [no] -qt3d-simd ........... Select level of SIMD support [no/sse2/avx2] -qt3d-render ......... Enable the Qt3D Render aspect [yes] -qt3d-input .......... Enable the Qt3D Input aspect [yes] -qt3d-logic .......... Enable the Qt3D Logic aspect [yes] -qt3d-extras ......... Enable the Qt3D Extras aspect [yes] -qt3d-animation....... Enable the Qt3D Animation aspect [yes] Further image format options: -jasper .............. Enable JPEG-2000 support using the JasPer library [no] -mng ................. Enable MNG support [no] -tiff ................ Enable TIFF support [system/qt/no] -webp ................ Enable WEBP support [system/qt/no] Multimedia options: -pulseaudio .......... Enable PulseAudio support [auto] (Unix only) -alsa ................ Enable ALSA support [auto] (Unix only) -no-gstreamer ........ Disable support for GStreamer -gstreamer [version] . Enable GStreamer support [auto] With no parameter, 1.0 is tried first, then 0.10. -evr ................. Enables EVR in WMF [auto] QtQuick3D options: -assimp .............. Select used assimp library [system/qt/no] WebEngine options: -webengine-alsa ................ Enable ALSA support [auto] (Linux only) -webengine-pulseaudio .......... Enable PulseAudio support [auto] (Linux only) -webengine-embedded-build ...... Enable Linux embedded build [auto] (Linux only) -webengine-icu ................. Use system ICU libraries [system/qt] (Linux only) -webengine-ffmpeg .............. Use system FFmpeg libraries [system/qt] (Linux only) -webengine-opus ................ Use system Opus libraries [system/qt] (Linux only) -webengine-webp ................ Use system WebP libraries [system/qt] (Linux only) -webengine-pepper-plugins ...... Enable use of Pepper Flash and Widevine plugins [auto] -webengine-printing-and-pdf .... Enable use of printing and output to PDF [auto] -webengine-proprietary-codecs .. Enable support for proprietary codecs [no] -webengine-spellchecker ........ Enable support for spellchecker [yes] -webengine-native-spellchecker . Enable support for native spellchecker [no] (macOS only) -webengine-webrtc .............. Enable support for WebRTC [auto]
cmd /? C:\Users\eric>cmd /? 启动 Windows 命令解释器的一个新实例 CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF] [[/S] [/C | /K] string] /C 执行字符串指定的命令然后终止 /K 执行字符串指定的命令但保留 /S 修改 /C 或 /K 之后的字符串处理(见下) /Q 关闭回显 /D 禁止从注册表执行 AutoRun 命令(见下) /A 使向管道或文件的内部命令输出成为 ANSI /U 使向管道或文件的内部命令输出成为 Unicode /T:fg 设置前台/背景颜色(详细信息见 COLOR /?) /E:ON 启用命令扩展(见下) /E:OFF 禁用命令扩展(见下) /F:ON 启用文件和目录名完成字符(见下) /F:OFF 禁用文件和目录名完成字符(见下) /V:ON 使用 ! 作为分隔符启用延迟的环境变量 扩展。例如,/V:ON 会允许 !var! 在执行时 扩展变量 var。var 语法会在输入时 扩展变量,这与在一个 FOR 循环内不同。 /V:OFF 禁用延迟的环境扩展。
–version # 打印版本信息
-v # 显示构建中的所有命令行(这个对实际构建的命令核对非常有用)
-C DIR # 在执行操作之前,切换到DIR目录
-f FILE # 制定FILE为构建输入文件。默认文件为当前目录下的build.ninja。如 ./ninja -f demo.ninja
-j N # 并行执行 N 个作业。默认N=3(需要对应的CPU支持)。如 ./ninja -j 2 all
-k N # 持续构建直到N个作业失败为止。默认N=1
-l N # 如果平均负载大于N,不启动新的作业
-n # 排练(dry run)(不执行命令,视其成功执行。如 ./ninja -n -t clean)
-d MODE # 开启调试模式 (用 -d list 罗列所有的模式)
-t TOOL # 执行一个子工具(用 -t list 罗列所有子命令工具)。如 ./ninja -t query all
-w FLAG # 控制告警级别
根据官方说明,profile则是在这两种之中取一个平衡,兼顾性能和调试,可以类似的看做是性能更优但是又方便调试的版本
使用Qt5.7版本对应三种模式编译的空白窗体程序大小:debug(1319kb)、release(24kb)、profile(90kb)
Qt源码编译configure配置参数
Qt6.2.2首发编译
记一次Qt 5.15源码编译
Deepin操作系统QT编译安装
WIN11环境下使用VS2022编译并部署QT6.2.2
Qt6.2.2源码编译及安装(Win10+VS2019)
从源码构建并安装Qt6
Building_Qt_6_from_Git
Qt for Windows - Building from Source
https://www.qt.io/blog/qt-6-build-system
其他操作系统平台构建方法 Building Qt Sources
QT运行时的Debug、Release、Profile选项区别
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。