-
Suggestion
-
Resolution: Won't Do
-
Not Evaluated
-
None
-
6.8
It is common to encounter situations where pointers managed by QSharedPointer are double-deleted, usually due to:
- QObject parent-child ownership – the parent deletes the child when it is destroyed.
- Interaction with QML – forgetting to set CppOwnership and passing a raw pointer to QML
Proposed Solution
Introduce a new smart pointer type with the following properties:
- Only accepts pointers derived from QObject.
- Add the functionality of the QPointer, the class instances get informed if the object is deleted.
- The default deletion method could then test if the object is already deleted and throw a Q_ASSERT and/or write a warning log.
- Optionally, the constructor could detect if the QObject already has a parent, and warn the user (to highlight potential double-deletion risks).