PDA

View Full Version : parent deletion.. what happens to child?



mahesh113
31st May 2012, 05:44
Deletion of parent widget will delete the child widget too.(Correct me if I am wrong).

now what will happen if we delete child explicitly after parent deletion.

something like --

delete *parent_widget;
delete *child_widget;

-Mahesh

ChrisW67
31st May 2012, 06:50
If parent_widget and child_widget are pointers to QWidgets then that code snippet will not compile.

You will probably get a "double free" warning if you are running a debug version and call delete on an object that has already been deleted. The easiest way to find out is to try these things.

sonulohani
1st June 2012, 12:13
Hey mahesh,
Just do one thing.
Always Allocate parent object as static memory allocation and allocate child objects as dynamic or static memory allocation whatever you want .
Then you dont have to delete anything as when the application will end up, it automatically deletes object that is allocated through static memory allocation. And there is one feature in Qt that is, if the parent object is deleted then it automatically deletes the child object.