Qt6快速安装方法
1 引言
与Qt5
不同,Qt6
不提供离线安装包,采用线上安装的形式。受限于国内网络环境,直接从官网安装Qt6
速度奇慢,甚至中途出现报错的情况比比皆是,这导致很多开发者没法在第一时间尝鲜Qt6
。为了解决这个痛点,本文提供两种安装Windows Qt6
的快速方法,并以安装Qt6.8.1
为例具体说明。
2 编译源码的安装方式
2.1 下载源码包
首先从常见国内镜像网站上下载qt-everywhere-src-6.8.1.zip
。笔者所用安装包从阿里镜像网站上下载,然后将源码包解压至全英文路径。
2.2 准备必要环境
Qt6
有很多常用模块,要想一次性成功编译这些模块,需要安装必要组件,分别是但不限于CMake
、Ninja
、Python3
、Nodejs
,安装完事之后需要将这些必要组件加入环境变量,确保其在windows cmd
环境中能够被识别。
2.3 编译步骤
Qt6的编译依赖于源码文件夹中configure.bat
,这是一个陌生命令,没事不用怕,--help
大法走起:
$(cwd)\build>..\configure --help | findstr /N .>out.txt
可以得到如下的帮助信息:
1:Usage: configure [options] [-- cmake-options]
3:This is a convenience script for configuring Qt with CMake.
4:Options after the double dash are directly passed to CMake.
5:You can pass CMake variables as configure arguments:
6: configure VAR=value
7:which is equivalent to
8: configure -- -DVAR=value
10:Top-level installation directories:
11: -prefix <dir> ...... The deployment directory, as seen on the target device.
12: [/usr/local/Qt-$QT_VERSION; qtbase build directory if
13: -developer-build]
14: -no-prefix ......... The deployment directory is set to the qtbase build
15: directory. Can be used instead of -developer-build
16: to not have to install, as well as avoid
17: -developer-build's default of -warnings-are-errors.
18: -extprefix <dir> ... The installation directory, as seen on the host machine.
19: [SYSROOT/PREFIX]
21:Fine tuning of installation directory layout. Note that all directories
22:except -sysconfdir should be located under -prefix:
24: -bindir <dir> ......... Executables [PREFIX/bin]
25: -headerdir <dir> ...... Header files [PREFIX/include]
26: -libdir <dir> ......... Libraries [PREFIX/lib]
27: -archdatadir <dir> .... Arch-dependent data [PREFIX]
28: -plugindir <dir> ...... Plugins [ARCHDATADIR/plugins]
29: -libexecdir <dir> ..... Helper programs [ARCHDATADIR/bin on Windows,
30: ARCHDATADIR/libexec otherwise]
31: -qmldir <dir> ......... QML imports [ARCHDATADIR/qml]
32: -sbomdir <dir> ....... Software Bill of Materials (SBOM)
33: installation directory [ARCHDATADIR/sbom]
34: -datadir <dir> ........ Arch-independent data [PREFIX]
35: -docdir <dir> ......... Documentation [DATADIR/doc]
36: -translationdir <dir> . Translations [DATADIR/translations]
37: -sysconfdir <dir> ..... Settings used by Qt programs [PREFIX/etc/xdg]
38: -examplesdir <dir> .... Examples [PREFIX/examples]
39: -testsdir <dir> ....... Tests [PREFIX/tests]
40: -hostdatadir <dir> .... Data used by qmake [PREFIX]
42:Conventions for the remaining options: When an option's description is
43:followed by a list of values in brackets, the interpretation is as follows:
44:'yes' represents the bare option; all other values are possible prefixes to
45:the option, e.g., -no-gui. Alternatively, the value can be assigned, e.g.,
46:--gui=yes. Values are listed in the order they are tried if not specified;
47:'auto' is a shorthand for 'yes/no'. Solitary 'yes' and 'no' represent binary
48:options without auto-detection.
50:Configure meta:
52: -help, -h ............ Display this help screen
53: -redo ................ Re-configure with previously used options. In addition,
54: redo removes CMakeCache.txt file and CMakeFiles/ directory
55: and recreates them from scratch.
56: Additional options may be passed, but will not be
57: saved for later use by -redo.
59: -feature-<feature> ... Enable <feature>
60: -no-feature-<feature> Disable <feature> [none]
61: -list-features ....... List available features. Note that some features
62: have dedicated command line options as well.
64:Build options:
66: -cmake-generator <name> ... Explicitly specify the build system generator for
67: CMake instead of auto-detecting one.
68: -cmake-use-default-generator ... Turn off auto-detection of the CMake build
69: system generator.
70: -cmake-file-api ...... Let CMake store build metadata for loading the build
71: into an IDE. [no; yes if -developer-build]
72: -no-guess-compiler ... Do not guess the compiler from the target mkspec.
73: -release ............. Build Qt with optimizations and without debug
74: symbols [yes]
75: Note that -developer-build implies -debug unless
76: -release is also explicitly specified
77: -debug ............... Build Qt without optimizations and with debug symbols
78: [no]
79: -debug-and-release ... Build two versions of Qt in one build tree [no]
80: -optimize-debug ...... Enable debug-friendly optimizations in debug builds
81: [auto] (Not supported with MSVC or Clang toolchains)
82: -optimize-size ....... Optimize release builds for size instead of speed [no]
83: -force-debug-info .... Create symbol files for release builds [no]
84: -separate-debug-info . Split off debug information to separate files [no]
85: -gdb-index ........... Index the debug info to speed up GDB
86: [no; auto if -developer-build with debug info]
87: -gc-binaries ......... Place each function or data item into its own section
88: and enable linker garbage collection of unused
89: sections. [auto for static builds, otherwise no]
90: -force-asserts ....... Enable Q_ASSERT even in release builds [no]
91: -developer-build ..... Compile and link Qt for developing Qt itself
92: (exports for auto-tests, extra checks, implies
93: -no-prefix, etc.) [no]
95: -shared .............. Build shared Qt libraries [yes] (no for UIKit)
96: -static .............. Build static Qt libraries [no] (yes for UIKit)
97: -framework ........... Build Qt framework bundles [yes] (Apple only)
99: -platform <target> ... Select mkspec for the qmake companion files
100: -device <name> ....... Select devices/mkspec for the qmake companion files
101: -device-option <key=value> ... Add option for the device mkspec
103: -appstore-compliant .. Disable code that is not allowed in platform app stores.
104: This is on by default for platforms which require distribution
105: through an app store by default, in particular Android,
106: iOS, tvOS, and watchOS. [auto]
108: -sbom ................ Enable generation of Software Bill of Materials (SBOM)
109: documents in SPDX tag:value format
110: [yes; no for developer builds]
111: -sbom-json ........... Enable SBOM generation in SPDX JSON format [auto]
112: (if Python dependencies are available)
113: -sbom-json-required .. Fails the build if the Python dependencies for JSON
114: generation are not found [no]
115: -sbom-verify ......... Verify generated SBOM files [auto] (if Python
116: dependencies are available)
117: -sbom-verify-required Fails the build if the Python dependencies for SBOM
118: verification are not found [no]
121: -qt-host-path <path> . Specify path to a Qt host build for cross-compiling.
122: -qtnamespace <name> .. Wrap all Qt library code in 'namespace <name> {...}'.
123: -qtinlinenamespace ... Make -qtnamespace an inline namespace
124: -qtlibinfix <infix> .. Rename all libQt6*.so to libQt6*<infix>.so.
126: -coverage <tool> ..... Instrument with the code coverage tool.
127: -gcov ................ Instrument with the GCov code coverage tool [no]
129: -trace [backend] ..... Enable instrumentation with tracepoints.
130: Currently supported backends are 'etw' (Windows),
131: 'lttng' (Linux), 'ctf' (Common Trace Format, cross-platform)
132: or 'yes' for auto-detection. [no]
134: -sanitize {address|thread|memory|fuzzer-no-link|undefined}
135: Instrument with the specified compiler sanitizer.
136: Note that some sanitizers cannot be combined;
137: for example, -sanitize address cannot be combined with
138: -sanitize thread.
140: -mips_dsp/-mips_dspr2 Use MIPS DSP/rev2 instructions [auto]
142: -qreal <type> ........ typedef qreal to the specified type. [double]
143: Note: this affects binary compatibility.
145: -R <string> .......... Add an explicit runtime library path to the Qt
146: libraries. Supports paths relative to LIBDIR.
147: -rpath ............... Link Qt libraries and executables using the library
148: install path as a runtime library path. Similar to
149: -R LIBDIR. On Apple platforms, disabling this implies
150: using absolute install names (based in LIBDIR) for
151: dynamic libraries and frameworks. [auto]
153: -reduce-exports ...... Reduce amount of exported symbols [auto]
154: -reduce-relocations .. Reduce amount of relocations [auto] (Unix only)
156: -plugin-manifests .... Embed manifests into plugins [no] (Windows only)
157: -static-runtime ...... With -static, use static runtime [no] (Windows only)
159: -pch ................. Use precompiled headers [auto]
160: -ltcg ................ Use Link Time Code Generation [no]
161: -intelcet ............ Use Intel Control-flow Enforcement Technology [auto]
162: -glibc-fortify-source Use Glibc function fortification [auto]
163: -trivial-auto-var-init-pattern
164: Use -ftrivial-auto-var-init=pattern [auto]
165: -stack-protector ..... Use -fstack-protector-strong [auto]
166: -stack-clash-protection
167: Use -fstack-clash-protection [auto]
168: -libstdcpp-assertions Use libstdc++ assertions [auto]
169: -libcpp-hardening .... Use libc++ hardening [auto]
170: -relro-now-linker .... Use -z relro -z now when linking [auto]
171: -linker [bfd,gold,lld,mold]
172: Force use of the GNU ld, GNU gold, LLVM/LLD or mold
173: linker instead of default one (GCC and clang only)
174: -ccache .............. Use the ccache compiler cache [no] (Unix only)
175: -unity-build ......... Enable Unity (Jumbo) build
176: -unity-build-batch-size <int>
177: Maximum number of source files used by the unity build
178: to create unity source files [32]
180: -warnings-are-errors . Treat warnings as errors [no; yes if -developer-build]
182: -disable-deprecated-up-to <version>
183: Set the QT_DISABLE_DEPRECATED_UP_TO value to <version>.
184: QT_DISABLE_DEPRECATED_UP_TO is used to remove
185: deprecated methods from both API and ABI.
186: <version> is a hex value, for example 0x060500 can be
187: used to remove all code deprecated in Qt 6.5.0 or
188: earlier releases.
189: By default <version> is set to 0x040000 and 0x050000 on
190: Windows, and non-Windows respectively.
192:Build environment:
194: -pkg-config .......... Use pkg-config [auto] (Unix only)
196: -vcpkg ............... Use vcpkg [no]
198: -D <string> .......... Pass additional preprocessor define
199: -I <string> .......... Pass additional include path
200: -L <string> .......... Pass additional library path
201: -F <string> .......... Pass additional framework path (Apple only)
203: -sdk <sdk> ........... Build Qt using Apple provided SDK <sdk>. The argument
204: should be one of the available SDKs as listed by
205: 'xcodebuild -showsdks'.
207: -android-sdk path .... Set Android SDK root path [$ANDROID_SDK_ROOT]
208: -android-ndk path .... Set Android NDK root path [$ANDROID_NDK_ROOT]
209: -android-ndk-platform Set Android platform
210: -android-abis ....... Only one ABI can be specified, default is: armeabi-v7a
211: -android-javac-target Set the javac build target version [8]
212: -android-javac-source Set the javac build source version [8]
213: -android-style-assets Automatically extract style assets from the device at
214: run time. This option makes the Android style behave
215: correctly, but also makes the Android platform plugin
216: incompatible with the LGPL2.1. [yes]
218:Component selection:
220: -submodules <repo>[,<repo>] ... Build the listed repositories and those they
221: depend on rather than all checked-out repositories.
222: The list should be separated with commas, e.g.
223: -submodules qtsvg,qtnetworkauth
224: [default is to build all checked out repositories]
225: -skip <repo>[,<repo>] Exclude one or more entire repositories from the
226: build. The list should be separated with commas.
227: e.g. -skip qtimageformats,qtsvg
228: -skip-tests <repo>[,<repo>] ... Skip building tests for one or more
229: repositories. The list should be separated with commas.
230: e.g. -skip-tests qtimageformats,qtsvg
231: -skip-examples <repo>[,<repo>] ... Skip building examples for one or more
232: repositories. The list should be separated with commas.
233: e.g. -skip-examples qtimageformats,qtsvg
234: -init-submodules ..... When configure is called from the qt git super module,
235: it will automatically clone and initialize the
236: repositories specified by the -submodules option. When
237: no -submodules are specified, and no existing
238: submodules are cloned, a default set of submodules
239: will be initialized. To adjust other aspects of the
240: cloning process, check the init-repository --help
241: output for additional options that can be passed
242: to configure.
243: -make <part> ......... Add <part> to the list of parts to be built.
244: Specifying this option clears the default list first.
245: (allowed values: libs, tools, examples, tests,
246: benchmarks, manual-tests, minimal-static-tests)
247: [default: libs and examples, also tools if not
248: cross-building, also tests if -developer-build]
249: -nomake <part> ....... Exclude <part> from the list of parts to be built.
250: -install-examples-sources Installs examples source code into the Qt prefix
251: Only possible when -make examples is also passed
252: [no]
253: -gui ................. Build the Qt GUI module and dependencies [yes]
254: -widgets ............. Build the Qt Widgets module and dependencies [yes]
255: -no-dbus ............. Do not build the Qt D-Bus module
256: [default on Android and Windows]
257: -dbus-linked ......... Build Qt D-Bus and link to libdbus-1 [auto]
258: -dbus-runtime ........ Build Qt D-Bus and dynamically load libdbus-1 [no]
259: -accessibility ....... Enable accessibility support [yes]
260: Note: Disabling accessibility is not recommended.
262:Qt comes with bundled copies of some 3rd party libraries. These are used
263:by default if auto-detection of the respective system library fails.
265:Core options:
267: -doubleconversion .... Select used double conversion library [system/qt/no]
268: No implies use of sscanf_l and snprintf_l (imprecise).
269: -glib ................ Enable Glib support [no; auto on Unix]
270: -inotify ............. Enable inotify support
271: -icu ................. Enable ICU support [auto]
272: -pcre ................ Select used libpcre2 [system/qt/no]
273: -zlib ................ Select used zlib [system/qt]
275: Logging backends:
276: -journald .......... Enable journald support [no] (Unix only)
277: -syslog ............ Enable syslog support [no] (Unix only)
278: -slog2 ............. Enable slog2 support [auto] (QNX only)
280:Network options:
282: -ssl ................. Enable either SSL support method [auto]
283: -no-openssl .......... Do not use OpenSSL [default on Apple]
284: -openssl-linked ...... Use OpenSSL and link to libssl [no]
285: -openssl-runtime ..... Use OpenSSL and dynamically load libssl [auto]
286: -schannel ............ Use Secure Channel [auto] (Windows only)
287: -securetransport ..... Use SecureTransport [auto] (Apple only)
289: -sctp ................ Enable SCTP support [no]
291: -libproxy ............ Enable use of libproxy [no]
292: -system-proxies ...... Use system network proxies by default [yes]
294:Gui, printing, widget options:
296: -cups ................ Enable CUPS support [auto] (Unix only)
298: -fontconfig .......... Enable Fontconfig support [auto] (Unix only)
299: -freetype ............ Select used FreeType [system/qt/no]
300: -harfbuzz ............ Select used HarfBuzz-NG [system/qt/no]
301: (Not auto-detected on Apple and Windows)
303: -gtk ................. Enable GTK platform theme support [auto]
305: -no-opengl ........... Disable OpenGL support
306: -opengl <api> ........ Enable OpenGL support. Supported APIs:
307: es2, desktop (default on Unix),
308: dynamic (Windows only, default on Windows)
309: -opengles3 ........... Enable OpenGL ES 3.x support instead of ES 2.x [auto]
310: -egl ................. Enable EGL support [auto]
312: -qpa <qpa1>[;<qpa2>] . Select supported QPA backend(s) (e.g., xcb, cocoa,
313: windows). A list separated by semi-colons.
314: -default-qpa <name> .. Select the default QPA backend (e.g., xcb, cocoa,
315: windows).
316: -xcb-xlib............. Enable Xcb-Xlib support [auto]
318: Platform backends:
319: -direct2d .......... Enable Direct2D support [auto] (Windows only)
320: -directfb .......... Enable DirectFB support [no] (Unix only)
321: -eglfs ............. Enable EGLFS support [auto; no on Android and Windows]
322: -gbm ............... Enable backends for GBM [auto] (Linux only)
323: -kms ............... Enable backends for KMS [auto] (Linux only)
324: -linuxfb ........... Enable Linux Framebuffer support [auto] (Linux only)
325: -xcb ............... Enable X11 support [auto] (Linux only)
327: Input backends:
328: -libudev............ Enable udev support [auto]
329: -evdev ............. Enable evdev support [auto]
330: -libinput .......... Enable libinput support [auto]
331: -mtdev ............. Enable mtdev support [auto]
332: -tslib ............. Enable tslib support [auto]
333: -bundled-xcb-xinput Use bundled XInput2 support [auto]
334: -xkbcommon ......... Enable key mapping support [auto]
336: Image formats:
337: -gif ............... Enable reading support for GIF [auto]
338: -ico ............... Enable support for ICO [yes]
339: -libpng ............ Select used libpng [system/qt/no]
340: -libjpeg ........... Select used libjpeg [system/qt/no]
342:Database options:
344: -sql-<driver> ........ Enable SQL <driver> plugin. Supported drivers:
345: db2 ibase mysql oci odbc psql sqlite mimer
346: [all auto]
347: -sqlite .............. Select used sqlite [system/qt]
349:Qt3D options:
351: -assimp .............. Select used assimp library [system/qt/no]
352: -qt3d-profile-jobs ... Enable jobs profiling [no]
353: -qt3d-profile-gl ..... Enable OpenGL profiling [no]
354: -qt3d-render ......... Enable the Qt3D Render aspect [yes]
355: -qt3d-input .......... Enable the Qt3D Input aspect [yes]
356: -qt3d-logic .......... Enable the Qt3D Logic aspect [yes]
357: -qt3d-extras ......... Enable the Qt3D Extras aspect [yes]
358: -qt3d-animation....... Enable the Qt3D Animation aspect [yes]
360:Further image format options:
362: -jasper .............. Enable JPEG-2000 support using the JasPer library [no]
363: -mng ................. Enable MNG support [no]
364: -tiff ................ Enable TIFF support [system/qt/no]
365: -webp ................ Enable WEBP support [system/qt/no]
367:Multimedia options:
369: -pulseaudio .......... Enable PulseAudio support [auto] (Unix only)
370: -alsa ................ Enable ALSA support [auto] (Unix only)
371: -no-gstreamer ........ Disable support for GStreamer
372: -gstreamer [version] . Enable GStreamer support [auto]
373: With no parameter, 1.0 is tried first, then 0.10.
374: -evr ................. Enables EVR in WMF [auto]
376:QtQuick3D options:
378: -assimp .............. Select used assimp library [system/qt/no]
379: -openxr .............. Select used OpenXR library [system/qt/no]
381:TextToSpeech options:
383: -flite ............... Enable Flite support [auto] (Unix only)
384: -flite-alsa .......... Enable Flite with ALSA support [auto] (Unix only)
385: -speechd ............. Enable speech dispatcher support [auto] (Unix only)
387:WebEngine options:
389: -webengine-alsa ................ Enable ALSA support [auto] (Linux only)
390: -webengine-pulseaudio .......... Enable PulseAudio support [auto]
391: (Linux only)
392: -webengine-embedded-build ...... Enable Linux embedded build [auto]
393: (Linux only)
394: -webengine-icu ................. Use system ICU libraries [system/qt]
395: (Linux only)
396: -webengine-ffmpeg .............. Use system FFmpeg libraries [system/qt]
397: (Linux only)
398: -webengine-opus ................ Use system Opus libraries [system/qt]
399: (Linux only)
400: -webengine-webp ................ Use system WebP libraries [system/qt]
401: (Linux only)
402: -webengine-pepper-plugins ...... Enable use of Pepper Flash and Widevine
403: plugins [auto]
404: -webengine-printing-and-pdf .... Enable use of printing and output to PDF
405: [auto]
406: -webengine-proprietary-codecs .. Enable support for proprietary codecs [no]
407: -webengine-spellchecker ........ Enable support for spellchecker [yes]
408: -webengine-native-spellchecker . Enable support for native spellchecker [no]
409: (macOS only)
410: -webengine-webrtc .............. Enable support for WebRTC [auto]
命令太多,快速扫描可以发现有debug和submod等字眼,进一步过滤帮助信息。可以得到得到与编译模式相关的信息:
\build>..\configure --help | findstr /N debug
73: -release ............. Build Qt with optimizations and without debug
75: Note that -developer-build implies -debug unless
77: -debug ............... Build Qt without optimizations and with debug symbols
79: -debug-and-release ... Build two versions of Qt in one build tree [no]
80: -optimize-debug ...... Enable debug-friendly optimizations in debug builds
83: -force-debug-info .... Create symbol files for release builds [no]
84: -separate-debug-info . Split off debug information to separate files [no]
85: -gdb-index ........... Index the debug info to speed up GDB
86: [no; auto if -developer-build with debug info]
也可以得到与子模块的相关信息:
..\configure --help | findstr /N mod
220: -submodules <repo>[,<repo>] ... Build the listed repositories and those they
223: -submodules qtsvg,qtnetworkauth
234: -init-submodules ..... When configure is called from the qt git super module,
236: repositories specified by the -submodules option. When
237: no -submodules are specified, and no existing
238: submodules are cloned, a default set of submodules
253: -gui ................. Build the Qt GUI module and dependencies [yes]
254: -widgets ............. Build the Qt Widgets module and dependencies [yes]
255: -no-dbus ............. Do not build the Qt D-Bus module
还可以得到安装路径相关的信息:
..\configure --help | findstr /N fix
11: -prefix <dir> ...... The deployment directory, as seen on the target device.
14: -no-prefix ......... The deployment directory is set to the qtbase build
18: -extprefix <dir> ... The installation directory, as seen on the host machine.
22:except -sysconfdir should be located under -prefix:
44:'yes' represents the bare option; all other values are possible prefixes to
93: -no-prefix, etc.) [no]
124: -qtlibinfix <infix> .. Rename all libQt6*.so to libQt6*<infix>.so.
250: -install-examples-sources Installs examples source code into the Qt prefix
目前已经获得所有重要命令,可以很容易的编写构建qt的命令:
..\configure -debug-and-release -prefix D:\Qt\Qt6.8.1
上面的命令代表分别构建debug和release两种模式下的qt库文件,并且安装路径在D:\Qt\Qt6.8.1
。
上面的步骤走完了,就可以使用CMake命令执行构建,具体命令如下:
cmake --build . --parallel
等待构建完成,然后使用如下命令进行安装即可。
cmake --install
3 线上安装工具安装
官网提供的线上安装工具速度很慢,可以通过命令行设置镜像服务器,并启动安装工具用于极大提升安装速度。具体步骤如下:
1、进入阿里镜像网站下载qt-online-installer-windows-x64-4.8.1.exe,然后进入cmd输入:
qt-online-installer-windows-x64-4.8.1.exe --help | findstr mir
可以得到与镜像服务器相关的命令:
--mirror <mirror> Uses the given mirror url
然后输入:
qt-online-installer-windows-x64-4.8.1.exe --mirror https://mirrors.aliyun.com/qt
即可进入快速安装模式。
4 结语
至此,两种快速安装qt6的方法介绍完成。需要说明的是,本文只对windows msvc qt版本有效,mingw等的操作方法与本文类似,但具体命令存在差异,望悉知。