You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

重装Windows后Qt项目路径变更引发构建失败求助

Qt构建错误:系统重装后路径变更导致文件找不到问题

系统重装Windows后项目路径变更,Qt构建时提示找不到旧路径C:\Users\...下的文件。已尝试删除过往构建文件和.pro.user文件,但问题依旧。

项目配置文件(files.pro)

QT += quick

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    main.cpp

RESOURCES += qml.qrc \
    images.qrc

# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =

# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

QML资源文件(qml.qrc)

<RCC>
    <qresource prefix="/">
        <file>main.qml</file>
        <file>Cell.qml</file>
        <file>SliderCell.qml</file>
        <file>Calendar1.qml</file>
        <file>Calendar2.qml</file>
        <file>FiltersCheckBox.qml</file>
        <file>DropDownListCell.qml</file>
    </qresource>
</RCC>

错误截图

Qt构建错误:无法找到旧路径文件


解决步骤

  • 检查images.qrc文件:错误提示的文件大概率在未贴出的images.qrc中,打开该文件查看<file>标签是否使用了旧系统的绝对路径,替换为项目内的相对路径即可。
  • 清理构建缓存:删除项目目录下的.cmake文件夹(若存在),如果用qmake则删除构建目录下的所有生成文件,重新执行qmake。
  • 重置Qt Creator构建配置:关闭Qt Creator,删除项目目录下的.pro.user文件后重新打开,在左侧「Projects」面板中删除旧的构建套件,重新添加新构建配置并指定新的构建目录。
  • 检查环境变量:确认系统中Qt相关环境变量(如QTDIR)指向当前安装的Qt路径,无旧系统残留路径。

内容的提问来源于stack exchange,提问作者psilll

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 21:45:29