Qt Creator构建Qt Quick应用失败:无法克隆指定Git仓库
解决Qt Creator创建Qt Quick Application时克隆仓库失败的问题
问题描述
在Qt Creator中创建新的Qt Quick Application项目,未做任何修改就构建失败,核心问题是无法克隆仓库https://code.qt.io/qt-labs/qtquickdesigner-components.git,浏览器也无法访问该地址,终端构建时提示连接code.qt.io的443端口超时。
关键错误片段:
fatal: unable to access 'https://code.qt.io/qt-labs/qtquickdesigner-components.git/': Failed to connect to code.qt.io port 443 after 75 ms: Couldn't connect to server CMake Error at ds-subbuild/ds-populate-prefix/tmp/ds-populate-gitclone.cmake:39 (message): Failed to clone repository: 'https://code.qt.io/qt-labs/qtquickdesigner-components.git'
解决方案
1. 替换仓库地址为GitHub官方镜像
Qt Labs的多数组件仓库在GitHub有官方镜像,修改项目中调用FetchContent的配置文件(通常是qmlcomponents或CMakeLists.txt),将仓库地址替换为镜像地址:
# 找到原有FetchContent_Declare配置,替换GIT_REPOSITORY字段 FetchContent_Declare( ds GIT_REPOSITORY https://github.com/qt-labs/qtquickdesigner-components.git GIT_TAG main # 可根据需求指定对应版本标签或commit哈希 )
保存后重新配置并构建项目。
2. 手动克隆仓库到本地,跳过自动下载
- 先手动将镜像仓库克隆到本地任意路径:
git clone https://github.com/qt-labs/qtquickdesigner-components.git /your/local/repo/path
- 在项目的CMakeLists.txt最顶部添加以下代码,指定本地仓库路径,让CMake直接使用本地代码:
set(FETCHCONTENT_SOURCE_DIR_DS /your/local/repo/path)
之后重新运行CMake配置并构建。
3. 排查网络代理设置
如果是网络环境限制导致无法访问code.qt.io,可配置git代理:
# 设置HTTP代理(替换为你的代理地址和端口) git config --global http.proxy http://proxy-address:port # 设置HTTPS代理 git config --global https.proxy https://proxy-address:port
若不需要代理,可重置代理设置:
git config --global --unset http.proxy git config --global --unset https.proxy
4. 使用无额外依赖的基础模板
如果不需要Qt Quick Designer组件,可选择更精简的项目模板:
在Qt Creator新建项目时,选择Qt Quick Application - Empty模板,该模板不会自动拉取额外组件仓库,避免克隆问题。
内容的提问来源于stack exchange,提问作者Alexy Ibrahim
相关产品推荐
相关产品推荐

