Qt6快速安装方法

1 引言

Qt5不同,Qt6 不提供离线安装包,采用线上安装的形式。受限于国内网络环境,直接从官网安装Qt6速度奇慢,甚至中途出现报错的情况比比皆是,这导致很多开发者没法在第一时间尝鲜Qt6。为了解决这个痛点,本文提供两种安装Windows Qt6的快速方法,并以安装Qt6.8.1为例具体说明。

2 编译源码的安装方式

2.1 下载源码包

首先从常见国内镜像网站上下载qt-everywhere-src-6.8.1.zip。笔者所用安装包从阿里镜像网站上下载,然后将源码包解压至全英文路径。

2.2 准备必要环境

Qt6有很多常用模块,要想一次性成功编译这些模块,需要安装必要组件,分别是但不限于CMakeNinjaPython3Nodejs,安装完事之后需要将这些必要组件加入环境变量,确保其在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 <
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值