Important: Please read the Qt Code of Conduct -

[Solved] How QQuickImageProvider is dealing with http url links?

  • Hi everyone,

    I have created a QQuickImageProvider class in a *.h file like this:


    #include <QObject>
    #include <QImage>
    #include <QQuickImageProvider>

    class ImageProvider : public QObject, public QQuickImageProvider
    ImageProvider() : QQuickImageProvider( QQuickImageProvider::Image,
    QQuickImageProvider::ForceAsynchronousImageLoading )

    QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize)
        return this->img;
    QImage img;


    #endif // IMAGEPROVIDER_H

    and after registering it in the main.cpp file, like this:

    qmlRegisterType<ImageProvider>( "com.example.ImageProvider", 1, 0, "ImageProvider" );
    QQmlApplicationEngine engine;
    engine.addImageProvider( QLatin1String("images"), new ImageProvider );

    I am trying to create a QML Image like this:

    Image {
    source: "image://images/"

    but then I get the error:

    QML Image: Failed to get image from provider: image://images/

    My question is: how can I get an image from a url using the qquickimageprovider???


  • Moderators


    Is it necessary for you to use QQuickImageProvider ?
    I mean you can directly use an http url as a source for Image element.

  • Thanks for your reply!

    I am now trying to a http url. However I have the following problem:
    The component is created before the download of the image is complete.
    Any idea?

  • Moderators

    bq. The component is created before the download of the image is complete.

    Yes since it may take some time for the image to load from the network.
    In case if you want to do operations when the image is completely loaded from the network you can use the "onStatusChanged": handler and the current status of the progress.

  • Thank you very very much! That worked! I hadn't notice that. I was using the Component.onCompleted which was creating the rest items before download to be complete!

    Thanks again! That saved a lot of time and effort!

  • Moderators

    You're welcome :)
    You can mark the post as solved by editing the post title and prepend [solved] so that others may know that it has been solved.
    Happy Coding :)

  • Thnx for the advice!

Log in to reply