【问题标题】:QML displayed camera photos in a ListView are destroyedQML 在 ListView 中显示的相机照片被破坏
【发布时间】: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


【解决方案1】:

我使用 camera.imageCapture 保存在磁盘上的图像解决了这个问题:

Camera{
  id:camera
  imageCapture {
    onImageSaved: {
      addPhotoInModel("file:///"+camera.imageCapture.capturedImagePath);
    }
  }
}

【讨论】:

    猜你喜欢
    • 2014-08-03
    • 1970-01-01
    • 2017-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-16
    • 1970-01-01
    • 2016-03-03
    相关资源
    最近更新 更多