Suppose, there is a lambda connected to a signal as below:
connect(pObject, &Object::mySignal, [] () { lambda; });
Will below statement disconnect the lambda automatically?
disconnect(pObject, &Object::mySignal, nullptr, nullptr);
I am asking this, because in the QObject::disconnect's documents there are 2 contradicting statements:
2 Disconnect everything connected to a specific signal:
disconnect(myObject, SIGNAL(mySignal()), nullptr, nullptr);
and
Note: It is not possible to use this overload to disconnect signals connected to functors or lambda expressions. That is because it is not possible to compare them. Instead, use the overload that takes a QMetaObject::Connection`
Just to clarify, the two quotes you gave are in fact from different
QObject::disconnectoverloads.In summary, the call...
should disconnect everything connected to the
MyObject::mySignalsignal of theMyObjectinstance pointed to bymyObject-- including lambdas/functors.I think the perceived contradiction comes from the fact that the second statement (the "Note") is rather badly worded. What it should state is...
Hence, given the 'mocked up' code...
it is not then possible to do...
If, however, you do as the quote says and...
then the following should work...
[Note: I don't have
Qtinstalled on the box, so the above is untested.]