QML在ListView中显示的相机照片被破坏

问题描述 投票:2回答:1

我用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

您可以在图片上看到,与预览4和7相对应的索引为3和6的图像不会显示,但是当创建包含索引的文本元素时,委托仍然存在。

enter image description here

这是代码:

//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}
  }
}

如果我使用本地图像而不是相机中的照片,我没有问题所以我想这可能是缓存问题,但为什么呢?

谢谢。

qt listview camera qml qt5
1个回答
1
投票

我使用camera.imageCapture保存在磁盘上的图像解决了它:

Camera{
  id:camera
  imageCapture {
    onImageSaved: {
      addPhotoInModel("file:///"+camera.imageCapture.capturedImagePath);
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.