Important: Please read the Qt Code of Conduct -

Image provider QImage requestImage() requestedSize is always -1

  • I’ve implemented an image provider (QImage requestImage ( const QString & id, QSize* size, const QSize& requestedSize))

    all works fine except that requestedSize is always -1, what did I do wrong?

    My code form the text.qml is as follows:
    id: img;
    x: 20;
    y: 20;
    width: 140;
    asynchronous: true;

       source: "image://thumbnailimage/Pictures/e1.jpg";


  • If I understand docs clearly 'The requestedSize corresponds to the Image::sourceSize requested by an Image element. If requestedSize is a valid size, the image returned should be of that size' you should check that if requestedSize is a valid size you should return image by that size. If it's not valid then you should return image by her real size.

    In your case, you didn't set property requestedSize so requestedSize in image provider would be -1. You should return original size of the image.

  • That was it

    by setting the following properties in qml
    sourceSize.width: 120;
    sourceSize.height: 100;

    that in turns set the QSize requestedSize in my image provider.

    Thanks for your help

Log in to reply