有没有办法在qml中使用图像占位符?

Is there any way to use image placeholder in qml?

目前我正在从服务器获取图片,所以有时加载需要一些时间,或者有时如果服务器上没有图片,图片位置显示空白。所以只要服务器图像未加载,我就需要显示 something/default 图像。 我尝试这样做,如果服务器上没有我正在加载图像的图像,那么我会尝试显示本地图像。 如果图片未从服务器正确加载,有什么方法可以显示默认图片。

  Image {
      id:img
      height: 100
      width: 300                                                                                                   
    Component.onCompleted: {                                                          
          if(there is no image on server){
                                                
           img.source="assets/images/someimage.png"
           }
           else{
          img.source="https://images.unsplash.com/photo-1503023345310-bd7c1de61c7d?ixid=MXwxMjA3fDB8MHxzZWFyY2h8MXx8aHVtYW58ZW58MHx8MHw%3D&ixlib=rb-1.2.1&w=1000&q=80"
           }
          }                                                         
  }

一个可能的解决方案是将一个图像放在主图像的顶部,并在加载它时隐藏初始图像:

Image {
    id: img
    width: 300 
    height: 100
    source: "https://images.unsplash.com/photo-1503023345310-bd7c1de61c7d?ixid=MXwxMjA3fDB8MHxzZWFyY2h8MXx8aHVtYW58ZW58MHx8MHw%3D&ixlib=rb-1.2.1&w=1000&q=80"
    Image{
        id: default_img
        anchors.fill: parent
        source: "assets/images/someimage.png"
        visible: img.status != Image.Ready 
    }
}