Search code examples
qtqmlqt-quick

Image element doesn't update when the image content changes with QDeclarativeImageProvider


I have a listview element like this :

ListView {
    id: view
    width: 200; height: 250
    model:myModel;
    delegate:
        Text{
            text:  bareJid + ' '+status;
            Image{
                source:image;
            }
        }
}

in the delegate Image element gets its image from a QDeclarativeImageProvider . but when the content of the image changes myModel doesn't update. How can I notice it to reload image when the content of the image has changed. thanks.


Solution

  • The Image item will not attempt to re-fetch the image at all unless the source is changed. Typically this is achieved by appending an id, which you can increment, to the end of the image name and dealing with that in your model and provider. You should also set cache: false since there is no point caching an image that is changing.

    Another possibility may be to set cache: false and change the image role first to "", and then back to the actual name, remembering to emit dataChanged after each change. Note that the image must not have previously been loaded with cache: true, or the cached version will be used regardless (this is fixed in QtQuick 2.0).