Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-37988

QQuickImageProvider can block its separate thread with ForceAsynchronousImageLoading

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Done
    • P2: Important
    • 5.5.0
    • 5.2.1
    • None
    • Windows 7 64-bit Mingw 48

    • f9c1b6e9c7ad3fbceef32590c5b7b6a9719fd453

    Description

      If two images are set to load from an image provider:

      //"test.qml"

      import QtQuick 2.0
      import QtQuick.Controls 1.1
      
      ApplicationWindow {
      
          width: 100
          height: 100
          visible: true
      
          Item {
              anchors.fill: parent
              focus: true
              Keys.onPressed: if(event.key === Qt.Key_Escape) Qt.quit()
      
              Image {
                  id: myImage
                  anchors {
                      left: parent.left
                      right: parent.right
                      top: parent.top
                      bottom: parent.verticalCenter
                  }
      
                  source: "image://myImageProvider/image1.png"
                  onStatusChanged: console.log("Image Status", status)
              }
      
              Image {
                  id: myImage2
                  anchors {
                      left: parent.left
                      right: parent.right
                      top: parent.verticalCenter
                      bottom: parent.bottom
                  }
                  source: "image://myImageProvider/image2.png"
                  onStatusChanged: console.log("Image Status", status)
              }
           }
      }
      

      If said image provider was as follows:

      MyImageProvider::MyImageProvider()
          : QQuickImageProvider(QQuickImageProvider::Pixmap, QQmlImageProviderBase::ForceAsynchronousImageLoading)
      {
      }
      
      QPixmap MyImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
      {
          QThread::sleep(2); // force a delay in returning from this function
      
          QPixmap pixmap;
      
          pixmap.load(id);
          if (requestedSize.isValid())
              pixmap = pixmap.scaled(requestedSize, Qt::IgnoreAspectRatio);
          *size = pixmap.size();
          return pixmap;
      }
      
      

      ... and set up like this:

      QQmlApplicationEngine testContent;
      testContent.addImageProvider("myImageProvider", new MyImageProvider);
      testContent.load("test.qml");
      

      ... image2 is loaded first, and then image1 is loaded afterwards.
      A quick look at QThread::currentThread confirms that whilst the requestPixmap function is indeed running in a different thread to the GUI thread, it is only running in ONE different thread - the asynchronous load of the Image components does not create multiple threads - only one - and in this case, image1 is made to wait for image2 which doesn't feel very asynchronous.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            tsdgeos_canonical Albert Astals Cid (Canonical) (Inactive)
            miketrahearn Mike Trahearn
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes