Results 1 to 7 of 7

Thread: Loading an image into memory

  1. #1
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

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

    Qt Code:
    1. //do something like a QGraphicsView::show();
    2. QPixmap pixmap("/path/to/file");
    To copy to clipboard, switch view to plain text mode 

    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!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.

  3. The following user says thank you to wysota for this useful post:

    Luc4 (10th April 2010)

  4. #3
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default 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.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.

  6. #5
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default 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!

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Loading an image into memory

    You can call it but it's unlikely it will actually terminate it inside the call

  8. #7
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default 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!

Similar Threads

  1. loading image from disk
    By freekill in forum Qt Programming
    Replies: 1
    Last Post: 18th February 2010, 05:21
  2. problems loading an image .jpg
    By maider in forum Qt Programming
    Replies: 3
    Last Post: 14th December 2009, 11:57
  3. Image Loading
    By kavinsiva in forum Qt Programming
    Replies: 2
    Last Post: 11th August 2009, 08:00
  4. QTextEdit and delayed image loading
    By Vladimir in forum Qt Programming
    Replies: 5
    Last Post: 27th April 2007, 08:13
  5. Loading a custom image into a QPixmap
    By KShots in forum Qt Programming
    Replies: 12
    Last Post: 5th August 2006, 00:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.