[Interest] Signal/Slot connection fails, even though QMetaObject::activate is called
Matthew Woehlke
mwoehlke.floss at gmail.com
Mon Feb 17 22:09:25 CET 2020
On 16/02/2020 21.33, Max Paperno wrote:
> Happened to stumble upon this clazy check while searching on a
> completely different issue.
> Seems to explain the reasoning pretty well.
>
> https://github.com/KDE/clazy/blob/master/docs/checks/README-connect-3arg-lambda.md
Thanks for sharing the link! This is good information for anyone that
doesn't understand the issue. One particular point to note is...
> On 2/15/2020 12:40 AM, Max Paperno wrote:
>> On 2/14/2020 11:19 PM, Tony Rietwyk wrote (in part):
>>> In the shorter overload, I would assume that the context is simply
>>> the current thread object.
...that this is wrong; a 3-arg connection *doesn't have* a context
argument. The connection will exist for as long as the sending object,
and you *don't know what thread it will execute in*.
Seriously. Let that sink in.
"Oh, well, it will run in the sender's thread," I hear you thinking.
NO! You *don't know that*!
I've written code that invokes signals in a thread other than the one to
which the owning object belongs. (Typically, for objects whose purpose
is to manage a worker thread.) With AutoConnection and a receiving
context this is generally safe (in fact, it is often the *purpose* of
such code to use the signals to pass data across threads), but if you
don't supply a context, your code might suddenly execute in what was
supposed to be a private worker thread.
Don't use context-free connections. Just don't ;-).
--
Matthew
More information about the Interest
mailing list