-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.0.0, 5.15.2, 6.2.4
-
None
-
Windows x64
I think there's an inconsistency between QObject and QWidget behaviour with respect to emitting destroyed signal and clearing of QPointers.
If I have a std::list<QPointer<QObject>> tracking some non-QWidget QObjects and want to remove items from the list when the QObject is destroyed I can connect to the destroyed signal and check if the QPointer isNull(), as per documentation https://doc.qt.io/qt-5/qobject.html#destroyed where is says "This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified".
However, if I have a std::list<QPointer<QWidget>> doing the same, then the QPointer is not cleared before destroyed is emitted. I think this is related to the change for QTBUG-24672 where destroyed is emitted in ~QWidget().
I have attached a project to demonstrate the difference in behaviour. The fix is relatively simple - in the lambda check if the object being destroyed is in the list.
I've only tried on Windows, but can't see why it would be any different on any other platform.
- relates to
-
QTBUG-106005 QWidget doesn't invalidate associated QPointer before emitting destroyed() signal
-
- Reported
-