Loading an image into memory
Hi! I noticed this situation a couple of times: I have a method which does something and then loads an image into memory, something like:
Code:
//do something like a QGraphicsView::show();
I get that the instructions before loading the image show results only after the pixmap is loaded. For instance, the QGraphicsView is shown only after the image is loaded (some seconds in slow devices and very large images). Is it possible somehow to change this behavior? I would prefer avoiding having to use threads if possible.
Thanks for any information!
Re: Loading an image into memory
You may only defer loading the pixmap to after you are sure the widget will already be visible. The latter happens when show() is called and processing returns to the event loop where appropriate events for showing the widget are processed. You can schedule your own event (or make a deferred slot call via QMetaObject::invokeMethod()) to load the image asynchronously. Of course you'll have to move all your code that uses the pixmap from the original function to somewhere after the pixmap is actually loaded.
Re: Loading an image into memory
Thanks for the information! And is it possible to terminate the loading of an image? I noticed it is not possible to terminate a thread while it is loading an image (this time I'm using the read method of QImageReader). Even if I call the terminate, the image is loaded completely anyway.
Re: Loading an image into memory
No, you can't interrupt the call as it's synchronous and performed mostly by 3rd party libraries that tend to behave differently.
Re: Loading an image into memory
I'm trying to load the image from a separate thread with low priority. In this case, can I call the terminate method of the thread to interrupt the loading?
Thanks again for your help!
Re: Loading an image into memory
You can call it but it's unlikely it will actually terminate it inside the call :)
Re: Loading an image into memory
OK, so no solution... :-( If I try to read an image which takes 8 seconds to load, I have to load it all, no matter what I do... Thanks anyway for your help!