【发布时间】:2018-03-19 16:07:43
【问题描述】:
我用 Camera 组件拍照并将它们添加到 ListView 中。问题是从一定数量的照片中,在我的测试中大约有 10 张,列表中的一些照片被破坏了,我收到以下错误:
QML Image: Failed to get image from provider: image://camera/preview_7
QML Image: Failed to get image from provider: image://camera/preview_4
您可以在图片上看到索引为 3 和 6 的图像,对应于预览 4 和 7,没有显示,但代理仍然存在,因为创建了包含索引的文本元素。
代码如下:
//the Camera
Camera{
id:camera
imageCapture {
onImageCaptured: {
addPhotoInModel(preview);
}
}
}
VideoOutput {
source: camera
anchors.fill: parent
}
//the ListView
function addPhotoInModel(image_url)
{
var imgId= calculateRandomId();
imagesListModel.append({"photoId": imgId,
"value":Qt.resolvedUrl(image_url)});
}
ListView{
....
model:imagesListModel
delegate:
Rectangle{
width:311; height:175;
Image{
width:parent.width; height:parent.height
source:model.value
}
Text{anchors.centerIn:parent; text:index}
}
}
如果我使用本地图像而不是相机中的照片,我没有问题,所以我猜这可能是缓存问题,但为什么呢?
谢谢。
【问题讨论】:
-
更正您的示例代码
with:311:height:175;
标签: qt listview camera qml qt5