Results 1 to 4 of 4

Thread: Loading an image in a thread

  1. #1
    Join Date
    Jan 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Loading an image in a thread

    Hi,

    I am working on a project in witch I need to display jpg files (about 4Mo each).

    I would like to be able to be able to load the next few files in a thread so the UI doesn't freeze.
    My problem is that I use a QPixmap on a QWidget to display those jpg and, apparently, Pixmap shouldn't be used outside the main thread.
    Therefore I'm stuck.

    Is there anyway to load the file from the HDD to the memory and then use the data (in which type?) to build my Pixmap in the main thread?

    If anyone has a suggestion as to how to load a big .jpg file in a thread, please let me know!

    Thx

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Loading an image in a thread

    Pixmap shouldn't be used outside the main thread.
    No.
    Only paint operations must be in the GUI thread.
    You can LOAD your pixmap in a worker thread, but SHOW it in the GUI thread.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Loading an image in a thread

    Oh...
    I guess I must have screwed up somewhere else 'cause I figured the strange behavior of my app was linked to that "problem".
    I'll keep trying then.
    Thx

  4. #4
    Join Date
    Jan 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: Loading an image in a thread

    Ok,
    everything works fine, my bad

    (The thing I was doing wrong was I was using a constructor QPixmap(QString filename) and even thought I didn't actually put it on screen it wouldn't work. QPixmap::load is the right answer)

    Thx again

Similar Threads

  1. Loading data in a thread
    By Cruz in forum Qt Programming
    Replies: 23
    Last Post: 28th October 2010, 17:18
  2. loading image from disk
    By freekill in forum Qt Programming
    Replies: 1
    Last Post: 18th February 2010, 05:21
  3. Image Loading
    By kavinsiva in forum Qt Programming
    Replies: 2
    Last Post: 11th August 2009, 08:00
  4. stylesheet loading issue - thread
    By talk2amulya in forum Qt Programming
    Replies: 8
    Last Post: 26th February 2009, 12:53
  5. Stop the thread during recursivly loading directory
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 14th May 2007, 19:02

Tags for this Thread

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.