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

QML项目添加图片无法加载求助:无法打开qrc:/design/logo.png

Fixing "QML Image: Cannot open: qrc:/design/logo.png" Error

Let's walk through the most common fixes for this issue—since your auto-complete works, the path makes logical sense, but the runtime can't locate the resource:

  • Double-check your .qrc resource file configuration
    Open your project's .qrc file and confirm the entry for your logo looks exactly like <file>design/logo.png</file>. Pay close attention to case sensitivity—if your actual folder is named Design instead of design, or the file is Logo.png, the path won't match on case-sensitive systems (like Linux/macOS).

  • Ensure the .qrc file is linked to your project

    • For Qt .pro projects: Verify your .pro file includes RESOURCES += your_resources.qrc (replace your_resources with your actual resource filename).
    • For CMake projects: Make sure you've added the resource file to your target with qt_add_resources() or qt_add_qml_module() (if using QML modules). Without this line, Qt won't compile the resources into your binary.
  • Clean and rebuild your project
    Stale build cache can sometimes prevent updated resources from being included. In Qt Creator, go to Build > Clean All, then Build > Rebuild All. This ensures the latest resource file is compiled into your app.

  • Test with an absolute file path (to rule out image corruption)
    Temporarily replace your source path with an absolute file URL like:

    source: "file:///home/yourusername/yourproject/design/logo.png"
    

    (Adjust the path to match your local setup.) If this loads the image, the problem is definitely with your resource setup, not the image file itself.

  • Verify the resource is actually compiled
    You can use the rcc tool to check if your resource file includes the logo. Run this in your terminal:

    rcc -list your_resources.qrc
    

    Look for design/logo.png in the output—if it's missing, the file wasn't properly added to the .qrc.


内容的提问来源于stack exchange,提问作者Sven van den Boogaart

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.13 08:45:47