[Interest] ImageProvider Threading

Gunnar Sletta gunnar at sletta.org
Fri Sep 18 09:08:36 CEST 2015

> On 18 Sep 2015, at 08:57, md at rpzdesign.com wrote:
> Gunnar:
> Thanks for the 5.6 doc link.
> Could not find anything that talks about parallel loading.  But if you 
> say it will provide parallel loading, what does the QML Image { } object 
> display while the image is loading?

The is an async api with a finished() signal which will tell the internal pixmap cahcing that the image is ready. If you put your implementation across multiple threads, it will be parallel. If you do all your loading on one thread, it will be serial. 

> I may want to return with a standard "Loading image..." image for those 
> images that are not found "slowly" in the background.

The Image element is kinda decoupled from the async loader logic. It only knows about its own status, which can be Null, Loading, Error or Ready.

When you set Image::source, it will enter Image::Loading. It will stay there until the QQuickImageProvider has completed its request and then the status will switch to either Image::Ready or Image::Error. 

> So what must be done is a way to cause Image { } to get refreshed later 
> after they return a temporary image just for speed purposes.

So what you want is to use two image elements, kinda like this:

Image {
    id: actualImage
    asynchronous: true
    source: "takesAWhileToLoad.png"
    anchors.fill: whatItIsSupposedtoFill

Image {
    id: tempImage
    asynchronous: false
    source: "myPlaceHolder.png"
    anchors.fill: whatItIsSupposedToFill
    visible: actualImage.status != Ready

The reason we don't provide a means of swapping out the image inside actualImage is that we don't know how you want to transition between the two. You can only decide that in your application. Your placeholder could be anything, a rectangle with a "loading..." text, or a small thumbnail or whatever. And when the switch happens, you could be using a Behavior to cross fade, etc. The above gives you full flexibility at the cost of an extra item.

If you want to use a single Image item, you will have to somehow connect your asynchronous loader to a signal that the actualImage catches. A bit more work, but also doable :)


> Thanks,
> md
> On 9/18/2015 12:29 AM, Gunnar Roth wrote:
>> Hi Mark,
>> I think it is serial. In Qt 5.6 there will be a new
>> QQuickAsyncImageProvider
>> <http://doc-snapshots.qt.io/qt5-5.6/qquickasyncimageprovider.html> class, with
>> it you can do parallel image loading/rendering.
>> Regards,
>> Gunnar Roth
>> *Gesendet:* Freitag, 18. September 2015 um 02:29 Uhr
>> *Von:* "mark diener" <rpzrpzrpz at gmail.com>
>> *An:* "interest at qt-project.org" <interest at qt-project.org>
>> *Betreff:* [Interest] ImageProvider Threading
>> Hello List:
>> When dealing with multi-threading, the docs say that QQuickImageProvider
>> will load
>> images in a separate low priority thread.
>> As it reads in the docs:
>> http://doc.qt.io/qt-5/qquickimageprovider.html#details
>> "When this is enabled, the image request to the provider is run in a low
>> priority thread, allowing image loading to be executed in the
>> background, and reducing the performance impact on the user interface."
>> Does anybody know if the requests are queued in a single low priority
>> thread or the requests are made in parallel low priority threads?
>> For queued, this means if we take a long time to return from
>> requestPixMap( ) that all the other images will block waiting for each
>> queued requestPixmap( ) call to complete.
>> Who knows, parallel or serial requestPixmap( ) calls?
>> Thanks,
>> md
>> _______________________________________________ Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
> -- 
> No spell checkers were harmed during the creation of this message.
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest

More information about the Interest mailing list