From 40a98ea750b90e453f552a1d1eb46b9947c951fa Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Tue, 10 Jul 2018 15:36:40 +0200 Subject: 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 --- src/corelib/doc/src/objectmodel/signalsandslots.qdoc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/corelib/doc/src/objectmodel/signalsandslots.qdoc b/src/corelib/doc/src/objectmodel/signalsandslots.qdoc index 6d3064d217..0cbbef0502 100644 --- a/src/corelib/doc/src/objectmodel/signalsandslots.qdoc +++ b/src/corelib/doc/src/objectmodel/signalsandslots.qdoc @@ -361,9 +361,11 @@ You can also connect to functors or C++11 lambdas: \code - connect(sender, &QObject::destroyed, [=](){ this->m_objects.remove(sender); }); + connect(sender, &QObject::destroyed, context, [=](){ this->m_objects.remove(sender); }); \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() and the \c{SIGNAL} and \c{SLOT} macros. The rule about whether to -- cgit v1.2.3