PDA

View Full Version : Loading an image in a thread



DarkyDuck
11th January 2011, 16:18
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

high_flyer
11th January 2011, 16:23
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.

DarkyDuck
11th January 2011, 16:33
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 :)

DarkyDuck
11th January 2011, 19:28
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