[Qt-interest] Fwd: QThread() examples
Sean Harmer
sean.harmer at maps-technology.com
Fri Dec 19 11:09:57 CET 2008
On Friday 19 December 2008 04:43:21 chandrasekar wagmare wrote:
> thank you very much .... same thing my boss told to me no use of changing
> GUI part in worker thread but what can i do ?... in my program one slot is
> running too long so in between the slot i try to update the text of QLabel
> to change but after the slot/event over only it repaints so i need to
> switch to thread but here now new problem came telling cant change the GUI
> in worker thread ... how can i resolve it ... please help ... i will
> look over the Qt Mandelbrot example now and any way
Although it is true that you can't directly update the GUI from a worker
thread, you can of course trigger an update to happen in the main thread. The
trick is to get your worker thread to emit a signal whenever you wish to cause
an update e.g. to a label or a progress bar. Then connect to this signal to an
object in the main thread that actually performs the update on the GUI. Please
check out the section on queued connections:
http://doc.trolltech.com/4.4/threads.html#signals-and-slots-across-threads
The Mandelbrot example you are looking at uses this technique. It "sends" the
QImage via the signal to the main thread for it to be painted on the screen.
In your case you may only be sending some progress info via a signal that you
emit periodically.
HTH,
Sean
More information about the Qt-interest-old
mailing list