Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.11.2
-
None
Description
The documentation of QMetaObject::Connection QObject::connect(const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type = Qt::AutoConnection) warns about this:
"The connection will automatically disconnect if the sender or the context is destroyed. However, you should take care that any objects used within the functor are still alive when the signal is emitted."
The naive developer, used to behaviour known from string-based connection where no manual handling is needed in case of slots being potentially triggered during destruction, might miss the detail that there are situations in the destructor where such a functor-based connection could be still triggered while already the destructor methods of subclasses have been reached. And which then behaves differently to string-based connections.
It might be an idea to be more explicit in the docs about this during-destructor-of-subclass-invoked-functor challenge.
I first had to be lucky to find http://lists.qt-project.org/pipermail/interest/2012-December/004975.html to understand why my code started to crash. Now it's obvious , but I would have preferred to know about it before, so I could have considered that before starting to design the code using context & functor-based connections.
So perhaps an addition like this might help other Qt users:
"The connection will automatically disconnect if the sender or the context is destroyed. However, you should take care that any objects used within the functor are still alive when the signal is emitted, e.g. if the functor is potentially invoked when already in the destructor of a subclass."