PDA

View Full Version : Accesing widgets from separate thread



msmihai
7th December 2008, 11:58
Hello again everybody.
Suppose i have a mainwindow with some widgets on it .
Now i want to create a separate thead and, in it's run() , to access the widgets from the mainwindow .

How can this be done ?

lyuts
7th December 2008, 12:51
In one of the recent posts i have read that you cannot access widgets from a separate non-gui thread.

tinsuke
8th December 2008, 11:48
You could do some interaction between the GUI and a non-GUI thread by using signals/slots. One separated thread could emit a signal changeLabelText(const QString&) thats connected to a QLabel::setText(const QString&) from the GUI-thread, the result is that the label setText call would be enqueued at the GUI thread event queue (it will only be effectively called on the Qt event handling thread, the GUI one).

Controlling widgets from outside the GUI thread is totally possible with some workarounds (I've implemented a win32 multithreaded GUI library port to linux and mac through Qt).

Take a look at
http://doc.trolltech.com/4.4/threads.html#threads-and-qobjects
for further info.