I have two QObject
s A
and B
living in separate QThread
s. A
will emit a signal while B
has a matching slot. I want to use connect()
to connect A
's signal to B
's slot.
So the question is, is the connect()
call thread safe? Does it matter in which of the two threads the connect is made?
Yes, QObject::connect() is thread safe method:
Note: All functions in this class are reentrant, but connect(), connect(), disconnect(), and disconnect() are also thread-safe.
It doesn't matter from which thread you do the connection. But you should care about using of auto connection
(default connection), unique connection
or queued connection between your objects. And you should run event loops in both of your threads.
Also I strongly suggest you to check following articles: first, second.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With