PDA

View Full Version : Invoke UI functions from a different thread ?



umanga
27th May 2010, 07:10
greetings all,

I execute my intensive process using "QConcurrent::run()" , within that process I need to call UI methods (update(),repaint() ..etc) to update and draw the graph according to the calculations.

But ,when I call repaint() , it throws "QPixmap: It is not safe to use pixmaps outside the GUI thread"

and for update() , I dont get the desired output.

Whats the best way to call UI methods from another thread?

thanks in advance.

tbscope
27th May 2010, 07:20
Create a signal to update the user interface from within the main thread.

Thus:
Your worker thread emits a signal, a slot in your mainwindow or widget etc... reacts to this signal a performs a repaint or update.

wysota
27th May 2010, 07:23
Use signals and slots to inform the main thread it should perform some graphical operation.

umanga
27th May 2010, 07:35
thanks tbscope for the reply,

I can define the slot but how do I define the signal in the thread because I use QConcurrent::run() .
Do I have to extends QThread class and define it?

tbscope
27th May 2010, 07:44
When you use run, you pass a function.
In that function emit the signal.