tags:

views:

62

answers:

2

I'm developing an application that gets large images from an Internet server which is the best way to download this images, without freeze the entire application? I mean background download. I have thought about download it in another thread.

A: 

Yes, you need to spawn another thread to do the network communication, and then when it is finished doing it's reading, you can use a volatile boolean flag to indicate that the work is complete and the main/application thread can take the data and incorporate it. The data may be "part" of an image if you want to show the image coming in piece by piece (as a browser does).

Jesse Pepper
A: 

A background thread will work, but it's tricky to get right and not usually necessary... Qt4 makes it very easy to do non-blocking I/O in the main thread using the QTcpSocket class -- basically you connect the QTcpSocket object's readReady() signal to a slot it your program, and have your slot read out the newly available data from the QTcpSocket when it is called. For an example, have a look at the fortuneclient example in the Qt examples directory ($QTDIR/examples/network/fortuneclient).

Jeremy Friesner