5

我有一个 qml 文件,这里是源代码:

import QtQuick 2.0

Image
{
    id: imageIcon;

    width: 100;
    height: 100;

    source: 'C:/Users/Public/Pictures/Sample Pictures/Chrysanthemum.jpg';
}

当我在 QQuickView 上显示它时,我收到此错误:

QML 图像:协议“c”未知

如果相关,我正在 Windows 7 上运行代码。

网址的正确格式是什么?

4

1 回答 1

11

看起来源必须使用格式正确的 URL:它需要一个file://方案或一个qrc://(用于 Qt 资源中的东西)

文件解析尝试使用未知的“C”协议(来自 C:/):尝试

source: 'file:///C:/Users/Public/Pictures/Sample Pictures/Chrysanthemum.jpg';

请参阅:http ://harmattan-dev.nokia.com/docs/platform-api-reference/xml/daily-docs/libqt4/qml-url.html

通常你想让你的图像相对(部署在你的应用程序附近)或嵌入到资源中,而不是绝对引用,因为这会破坏部署。

于 2013-07-12T08:47:56.303 回答