On 04/05/16 19:09, Nye wrote:
[...]
Is there a Qt-specific idiom where I can manage QObjects that have a
parent with a smart pointer and not have to worry about double-deletion?
The parent will be notified of the child's deletion, so it's generally
safe to delete the child directly (with a few somewhat rare exceptions).
So most of the time QScopedPointer or it's STL equivalent work just
fine. If you need a guarded pointer for when Qt might delete the object
while you still hold a reference, you can use QPointer. I personally
detest the unnecessary new, and just create everything with auto storage
where it's possible. So that's another way you can eliminate new almost
completely.
From what I can tell, QPointer does not delete the object, so that's a
no go.
Putting the objects on the stack doesn't work either, because the Qt
object model does not support that (it will call 'delete' on the object
even if it's on the stack.)
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest