Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Automatic deletion of QObjects
ModelTech last edited by
In my application, I am currently doing the deletion of QObjects myself (too much of traditional C++ history perhaps...). I would however like to introduce undo/redo functionality in my application and from the undo example that comes with Qt (http://doc.qt.io/qt-5/qtwidgets-tools-undo-example.html), I understand that the QObjects (in this case diagram items) are not really destroyed but only removed from the scene on a delete action by the user. By keeping the diagram item in memory, the action can be undone. As I intend to limit the undo stack size, I would like to have the objects destroyed at the moment that the stack size limit is reached. So, my question is actually: will QObjects be destroyed automatically if there are no references to them anymore (with or without having a parent)?
If the objects don't have any parent then no.