QML项目添加图片无法加载求助:无法打开qrc:/design/logo.png
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 namedDesigninstead ofdesign, or the file isLogo.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
.profile includesRESOURCES += your_resources.qrc(replaceyour_resourceswith your actual resource filename). - For CMake projects: Make sure you've added the resource file to your target with
qt_add_resources()orqt_add_qml_module()(if using QML modules). Without this line, Qt won't compile the resources into your binary.
- For Qt .pro projects: Verify your
Clean and rebuild your project
Stale build cache can sometimes prevent updated resources from being included. In Qt Creator, go toBuild > Clean All, thenBuild > 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 thercctool to check if your resource file includes the logo. Run this in your terminal:rcc -list your_resources.qrcLook for
design/logo.pngin the output—if it's missing, the file wasn't properly added to the .qrc.
内容的提问来源于stack exchange,提问作者Sven van den Boogaart

