[Qt-interest] Sending a qt signal from pthreads

K. Frank kfrank29.c at gmail.com
Tue Feb 8 00:37:44 CET 2011


Hi Thiago!

I would like to ask some related questions to strengthen
my understanding.

On Mon, Feb 7, 2011 at 5:32 PM, Thiago Macieira <thiago at kde.org> wrote:
> On Monday, 7 de February de 2011 18:31:59 Gheorghe Marinca wrote:
>> Hi,
>>
>> I have a linux application that uses pthreads. I want to be able from the
>> context of the pthread (I have a class derived from QObject that get called
>> from inside some pthread "legacy" code )
>> to be able to send qt signals to other qt classes. If this is possible than
>> I guess the usual mechanism of signal/slots work in this case also - if the
>> object that receives the signals is from main qt thread than it will receive
>> the slot calls inside the main thread.
>
> Signal delivery depends only on the thread of the target object. It doesn't
> depend on the source thread, much less how it was started.

First:

If I spawn a pthread, and that pthread creates some sort of
QObject, what is the tread affinity of that QObject?

I'm thinking that because the thread of execution that created
the object is a "foreign" thread (a pthread), it is not managed by
a QThread object.  So is the thread affinity of the pthread-created
object "none" or some kind of default value?

Second:

If a signal and slot are connected with an "auto" connection,
my understanding is that whether the slot is called synchronously
("direct" connection) or asynchronously ("queued" connection)
is determined by the thread of execution that emits the signal,
and the thread affinity of the object whose slot receives the signal:
if the signal thread is the same as the slot thread, the call is
synchronous, and if they are different, the call is queued.

What then happens, for example, if pthread A emits a signal
from object A, and that signal is connected to a slot in object
B, where object B was created by pthread B?  Since both the
signal thread and the slot thread are "foreign" threads, how
does the Qt framework decide whether the call should be
synchronous or asynchronous?

It's not clear to me how an asynchronous call (queued connection)
could be implemented, since pthread B doesn't have an associated
QThread object to which events can be posted, and presumably
isn't running an event loop that could process such events.

Just curious...

Thanks.


K. Frank


> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
>  Senior Product Manager - Nokia, Qt Development Frameworks



More information about the Qt-interest-old mailing list