Hello,

My question is about the undoframework http://doc.qt.io/qt-5/qtwidgets-tool...k-example.html and http://doc.qt.io/qt-5/qtwidgets-tool...mands-cpp.html

The AddCommand class has a destructor :

Qt Code:
  1. AddCommand::~AddCommand()
  2. {
  3. if (!myDiagramItem->scene())
  4. delete myDiagramItem;
  5. }
To copy to clipboard, switch view to plain text mode 

Let's say that the stored item, myDiagramItem, is inside a scene. The scene has the responsability to delete it. So I wonder how this destructor can work because if the destructor of the scene is called before the destructor of AddCommand the pointer myDiagramItem will be invalid, so the first line (if (!myDiagramItem->scene()) ) should lead to a crash. How can we be sure that it will not happened ?


Second question, it seems that diagramScene stored in MainWindow doesn't have any parent, so how the memory of diagramScene is released ?
(See : http://doc.qt.io/qt-5/qtwidgets-tool...indow-cpp.html)

Thank you very much for your help.