从 Git 仓库获取 Qt 源代码
本页介绍如何从公共 Git 仓库获取 Qt 源代码。这些 Git 仓库包含 Qt 6 的最新开发分支和已发布版本。
您还可以通过Qt Online Installer 、您的Qt 账户(商业用户)或download.qt.io(开源用户)获取 Qt 源代码。
在初始化 Git 子模块时,您需要安装最新版本的Git和CMake 文档才能运行init-repository 工具。
注意:本指南假设您 熟悉命令行工具的使用。
克隆 Qt 存储库
Qt 在主qt5.git 存储库中的多个 Git 子模块中进行开发和维护。从 Git 获取 Qt 源代码需要通过命令行克隆顶级 Git 存储库。
注意:Qt 5 和 Qt 6 共用同一个仓库qt5.git ,因此即使您使用 Qt 6,获取的也是 Qt 5 仓库。
本指南采用类 Unix 壳层语法。在 Windows 系统上,相关命令类似。以下命令将 Qt 6 的当前版本克隆到名为qt 的目录中。
git clone --branch v6.12.0 git://code.qt.io/qt/qt5.git qt如果您的防火墙屏蔽了 git 协议,请考虑改用 HTTPS:
git clone --branch v6.12.0 https://code.qt.io/qt/qt5.git qt克隆完成后,qt 目录中将包含 Qt 主 Git 仓库,其中包含设置文件和尚未初始化的 Qt 子模块。
初始化 Qt 子模块
qt5.git 仓库将Qt 模块作为 Git 子模块包含其中。要初始化并克隆这些子模块,请在顶级目录中运行init-repository 工具。
./init-repository在 Windows 系统上,若无 Linux 环境,请改用init-repository.bat 。
init-repository.batinit-repository 该工具会克隆并初始化设置文件,以便构建 Qt 源代码。此外,该仓库中还包含一些工具,可帮助 Qt 贡献者创建补丁、测试代码以及生成文档。有关贡献的更多信息,请访问“为 Qt 贡献”网站。
如果您在同一目录下已有 Qt 仓库,可以传入-f 参数,强制init-repository 重新初始化子模块。
./init-repository -f初始化 Qt 特定的子模块
如果您只需要特定的 Qt 模块集,请将 `--module-subset ` 作为 `init-repository` 的参数,以初始化最小的子模块集。例如,您可以通过指定 `essential ` 作为参数,仅初始化Qt Essentials模块。
./init-repository --module-subset=essential对于Qt 附加组件,请改用addon 。
./init-repository --module-subset=addon您还可以同时选择多个子模块。例如,要初始化qtgrpc 和qtmqtt 子模块及其所需的子模块,请运行:
./init-repository --module-subset=qtgrpc,qtmqttinit-repository 工具始终会初始化一组最少的子模块。
如需了解更多信息,请将-help 作为参数设置,查阅init-repository 手册:
./init-repository -help克隆并初始化后
下一步是配置和构建 Qt。请阅读“构建 Qt 源代码”页面以获取更多信息。
© 2026 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.