【发布时间】:2014-11-25 07:59:52
【问题描述】:
这看起来很基本,但由于某种原因,我无法让图像源在下面的超简单 QML 应用程序中工作。
仅供参考,我正在运行 Mac OS-X 10.9.5,基于 Qt 5.3.2 的 Qt Creator 3.2.1。
import QtQuick 2.3
import QtQuick.Controls 1.2
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Test")
Image {
id: image1
x: 10
y: 10
width: 100
height: 100
source: "testImage.png"
}
}
我收到以下错误:
qrc:/main.qml:10:5: QML Image: Cannot open: qrc:/testImage.png
应用程序窗口已创建,但没有显示图像。我也尝试将图像包装在 Rectangle 中,但这没有帮助。
我在这里做错了什么?
“testImage.png”在项目目录中,我尝试了各种方法来使用资源指定图像路径,绝对、相对,甚至使用 QML UI 设计器手动指定图像源。
我还要提到,为了让 Qt 5.3.2 工作,我遵循了建议的修改 HERE。
谢谢。
【问题讨论】:
-
doc.qt.io/qt-5/qml-qtquick-image.html#source-prop
The URL may be absolute, or relative to the URL of the component.qrc URL 是相对的。您也可以使用 file:///home/user/testImage.png ,或者您可以定义自己的 QQuickImageProvider 来处理您自己的方案,例如Image { source: "image://myimageprovider/testImage.png" }