Use context when connecting to functors in docs
This is the introduction text to signals and slots and should rather show best practices. Using context is generally advisable to have life-time of connections under control. Change-Id: I213b13d978a38e13834cdbccf1bea06d53ba8320 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
parent
582d221b29
commit
40a98ea750
@ -361,9 +361,11 @@
|
|||||||
You can also connect to functors or C++11 lambdas:
|
You can also connect to functors or C++11 lambdas:
|
||||||
|
|
||||||
\code
|
\code
|
||||||
connect(sender, &QObject::destroyed, [=](){ this->m_objects.remove(sender); });
|
connect(sender, &QObject::destroyed, context, [=](){ this->m_objects.remove(sender); });
|
||||||
\endcode
|
\endcode
|
||||||
|
|
||||||
|
The lambda will be disconnected when the context is destroyed.
|
||||||
|
|
||||||
The other way to connect a signal to a slot is to use QObject::connect()
|
The other way to connect a signal to a slot is to use QObject::connect()
|
||||||
and the \c{SIGNAL} and \c{SLOT} macros.
|
and the \c{SIGNAL} and \c{SLOT} macros.
|
||||||
The rule about whether to
|
The rule about whether to
|
||||||
|
Loading…
x
Reference in New Issue
Block a user