[Qt-interest] emit signal from spawned thread

Jason H scorp1us at yahoo.com
Fri Aug 19 21:08:09 CEST 2011


Ok, perhaps I an confused, but it sounds like you want a QRunnable to emit something to something else.
To which I suggested, don't worry about not being able to identify the QRunnable, have the QRunnable identify the signal target for connection. 


For instance you could use a singleton object and connect directly to that in your run() or use the singleton to map the signal to other objects. You's need to register the slot object and selection criteria ahead of starting the runnable, 

singleton->registerMe(this, forInstanceId); 
but when the singleton is used in run it can supply the this pointer. 

singleton->connectMe(this, thisInstanceId); 


Where the instance id is some way to uniquely identify it, probably by the data it is working on. At which point in time, the singleton has both objects needs only the specific signal/slots to map. I'll leave that as an exercise to the reader.





________________________________
From: Guido Seifert <wargand at gmx.de>
To: TrolltechInterest <qt-interest at trolltech.com>
Sent: Friday, August 19, 2011 2:37 PM
Subject: Re: [Qt-interest] emit signal from spawned thread

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
_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110819/b23cfe43/attachment.html 


More information about the Qt-interest-old mailing list