[Qt-interest] emit signal from spawned thread

Guido Seifert wargand at gmx.de
Fri Aug 19 20:37:08 CEST 2011


Jason, this wasn't the original question. Doing things like that using
QRunnable or QThread is easy. The question was how to connect to a
signal, which is emitted in a function, which is passed to
QtConcurrent::run.

I never looked how QtConcurrent is implemented. According to its docs,
this function is run within a thread taken from the global
QTreadPool. Thiago surely has deeper knowledge, I, however, don't see
a way to get access to this 'unnamed' object from the theadpool to
make a signal/slot connection. 

So it is surely possible to emit signals from such a function, but it
might be utterly useless.

Guido


On Fri, Aug 19, 2011 at 11:30:17AM -0700, Jason H wrote:
> Your QRunnable::run() would need some way to identify its signal target, and then it could connect() in the run.
> 
> I would try inheriting from QRunnable and have a setSignalTarget(QObject*) wherein it could in run() {
> connect(this, mysignal, target, slot)
> }
> 
> It's the same trick used in making TCP servers multithreaded, where you set the socketDescriptor (an int)  then in the run, you pick up that descriptor and run with it, pun partially intented.
> 
> 
> 
> ________________________________
> From: Guido Seifert <wargand at gmx.de>
> To: TrolltechInterest <qt-interest at trolltech.com>
> Sent: Friday, August 19, 2011 2:10 PM
> Subject: Re: [Qt-interest] emit signal from spawned thread
> 
> 
> > > automatic connections, but you should be able to emit your own signals.
> > 
> > You can emit signals from anywhere.
> 
> Sure. But du you see a way to connect to a signal emitted from a
> function passed to QtConcurrent::run?
> 
> Guido
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest



More information about the Qt-interest-old mailing list