PDA

View Full Version : Communication between QRunnable and main thread



Windsoarer
27th December 2010, 19:45
Hi all,

To tell the user that the QRunnable threads have not stalled, I would like them to provide some feedback to the main GUI. But QRunnable does not inherit QObject, hence doesn't seem to provide the capability of signal emission.
So, how can a QRunnable thread communicate to the main thread ?

Thanks

Andre

high_flyer
27th December 2010, 21:00
I see two options for signaling from a QRunnbale:
1. Since QRunnable is not a QObject, you can multiple inherit from QObject:


class MyRunnable : public QRunnable, public QObject
{
...
};


Note - at least in theory - I didn't try it.

The other option is to have a member in your QRunnable which is a QObject, and signal from that object.

Windsoarer
27th December 2010, 22:27
I'll try, thanks

Windsoarer
28th December 2010, 06:43
Just for information, I found a way using postEvent() from the QRunnable thread to the main thread.

high_flyer
28th December 2010, 08:52
Yes, that is true, you can always send an event, and before Qt4.X that was the only way to "signal" between threads (signals where not possible)
But you asked about sending signals, so...