Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [Solved] How QQuickImageProvider is dealing with http url links?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 2 Posters 2.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cochleas.devel
    wrote on last edited by
    #1

    Hi everyone,

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

    #ifndef IMAGEPROVIDER_H
    #define IMAGEPROVIDER_H

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

    class ImageProvider : public QObject, public QQuickImageProvider
    {
    public:
    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 );
    engine.load(QUrl(QStringLiteral("qrc:///main.qml")));

    I am trying to create a QML Image like this:

    Image {
    source: "image://images/http://static.giantbomb.com/uploads/scale_small/0/6393/528516-1ball2.jpg"
    }

    but then I get the error:

    QML Image: Failed to get image from provider: image://images/http://static.giantbomb.com/uploads/scale_small/0/6393/528516-1ball2.jpg


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

    Thanx!

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

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

      157

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cochleas.devel
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          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":http://qt-project.org/doc/qt-5/qml-qtquick-image.html#status-prop handler and the current status of the progress.

          157

          1 Reply Last reply
          0
          • C Offline
            C Offline
            cochleas.devel
            wrote on last edited by
            #5

            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!

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              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 :)

              157

              1 Reply Last reply
              0
              • C Offline
                C Offline
                cochleas.devel
                wrote on last edited by
                #7

                Thnx for the advice!

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved