QML ImageProvider 类不能刷新Image的解决方法

在编写QML中发现一个问题,在多次调用 

image.souce = "image://imageprovider"
中, ImageProvider 类中的 requestImage () 只执行一次。查官网后发现如下解释。

Images returned by a QQuickImageProvider are automatically cached, similar to any image loaded by the QML engine. When an image with a "image://" prefix is loaded from cacherequestImage() and requestPixmap() will not be called for the relevant image provider. If an image should always be fetched from the image provider, and should not be cached at all, set the cache property to false for the relevant ImageBorderImage or AnimatedImage object.

意思是,QQuickImageProvider 返回的类是默认缓存的,如果已经载入图片后, requestImage() 不会再被调用。所以如果图像确定总是要从image provider 中获取,需要将QML中 Image 的 cache 属性至为 false。更新图片需要如下两行语句:

image.source = "";
image.source = "image://images";


  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值