在本页中

从 Git 仓库获取 Qt 源代码

本页介绍如何从公共 Git 代码库中获取 Qt 源代码。Git 仓库包含 Qt 6 的最新开发分支和发布版本。

您也可以通过Qt Online InstallerQt Account(商业用户)或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 的 shell 语法。在 Windows 上,命令也类似。下面的命令将当前版本的 Qt 6 克隆到一个名为qt 的目录中。

git clone --branch v6.11.0 git://code.qt.io/qt/qt5.git qt

如果防火墙阻止了 git 协议,请考虑使用 HTTPS 代替:

git clone --branch v6.11.0 https://code.qt.io/qt/qt5.git qt

克隆后,qt 目录包含 Qt Git 主仓库,其中有设置文件和未初始化的 Qt 子模块。

初始化 Qt 子模块

qt5.git 仓库包含作为 Git 子模块的 Qt 模块。要初始化和克隆子模块,请在顶层目录中运行init-repository 工具。

./init-repository

在 Windows 上,如果没有 Linux 环境,请使用init-repository.bat

init-repository.bat

init-repository 克隆和初始化设置文件,以构建 Qt 源代码。此外,软件源中还有一些工具,可帮助 Qt 贡献者创建补丁、测试代码和生成文档。有关贡献的更多信息,请访问Contributing to Qt网站。

如果同一目录下已有 Qt 代码库,可通过-f 强制init-repository 重新初始化子模块。

./init-repository -f

初始化 Qt 特定子模块

如果你只需要一组特定的 Qt 模块,可使用--module-subset 作为init-repository 的参数,初始化一组最小的子模块。例如,你可以通过指定essential 作为参数,只初始化Qt Essentials模块。

./init-repository --module-subset=essential

对于Qt Add-Ons,请使用addon 代替。

./init-repository --module-subset=addon

您还可以同时选择多个子模块。例如,要初始化qtgrpcqtmqtt 子模块及其所需的子模块,请运行:

./init-repository --module-subset=qtgrpc,qtmqtt

init-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.