PDA

View Full Version : Deleting a QWidget derived object manually



hubbobubbo
3rd February 2010, 13:18
Hi

I just wanted to check if this is ok.

I have a StackedView that can contain zero or more of my custom Widgets. As it is now all my Widgets has the StackedView as parent so when it is deleted, so are the widgets. However the Widgets are created and disposed dynamically during the execution of my program. In some scenarios I really want to delete the Widget in the StackedView immidiatly and not wait for the StackedView to be deleted.

So my question is simply. If I have a Widget that has a parent QWidget, is it good practice to sometimes delete the widget manually and still keep the parent deletion as a backup option?

aamer4yu
4th February 2010, 04:56
Its fine enough to delete yourself. The children which has been deleted wont be deleted again when the parent is deleted.
Qt eases you not to bother about child deletions but doesnt restrict you from manually doing it.

JohannesMunk
4th February 2010, 16:32
Your question was if it is good practice. My answer is: As long as you as the developer can easily keep up where and why something happens, everything is fine. Qt obviously is designed for that practice, because of the existence of QEvent::ChildRemoved and QChildEvent.

Johannes