Qt 列表视图中显示的QML相机照片将被销毁
我使用相机组件拍摄照片,并将其添加到列表视图中。问题是,在我的测试中,从一定数量的照片(大约10张)中,列表中的一些照片被销毁,我得到以下错误:Qt 列表视图中显示的QML相机照片将被销毁,qt,listview,camera,qml,qt5,Qt,Listview,Camera,Qml,Qt5,我使用相机组件拍摄照片,并将其添加到列表视图中。问题是,在我的测试中,从一定数量的照片(大约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)的图像不会显示,
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}
}
}
如果我使用本地图像而不是相机中的照片,我没有问题,所以我猜这可能是缓存问题,但为什么
谢谢。我用相机保存在磁盘上的图像解决了这个问题。imageCapture:
Camera{
id:camera
imageCapture {
onImageSaved: {
addPhotoInModel("file:///"+camera.imageCapture.capturedImagePath);
}
}
}
使用:311:height:175更正示例代码
代码>