nilot
9th February 2017, 09:29
Hello,
My question is about the undoframework http://doc.qt.io/qt-5/qtwidgets-tools-undoframework-example.html and http://doc.qt.io/qt-5/qtwidgets-tools-undoframework-commands-cpp.html
The AddCommand class has a destructor :
AddCommand::~AddCommand()
{
if (!myDiagramItem->scene())
delete myDiagramItem;
}
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-tools-undoframework-mainwindow-cpp.html)
Thank you very much for your help.
My question is about the undoframework http://doc.qt.io/qt-5/qtwidgets-tools-undoframework-example.html and http://doc.qt.io/qt-5/qtwidgets-tools-undoframework-commands-cpp.html
The AddCommand class has a destructor :
AddCommand::~AddCommand()
{
if (!myDiagramItem->scene())
delete myDiagramItem;
}
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-tools-undoframework-mainwindow-cpp.html)
Thank you very much for your help.