Results 1 to 3 of 3

Thread: parent deletion.. what happens to child?

  1. #1
    Join Date
    May 2012
    Posts
    4
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default parent deletion.. what happens to child?

    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

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: parent deletion.. what happens to child?

    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.

  3. #3
    Join Date
    May 2012
    Location
    Bangalore, India
    Posts
    271
    Thanks
    29
    Thanked 50 Times in 47 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Cool Re: parent deletion.. what happens to child?

    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.

Similar Threads

  1. styling parent but not child?
    By ugluk in forum Qt Programming
    Replies: 3
    Last Post: 13th October 2011, 02:55
  2. Parent child relationship in Qt
    By TheIndependentAquarius in forum Newbie
    Replies: 18
    Last Post: 14th July 2011, 08:43
  3. Parent Child for window
    By febil in forum Qt Programming
    Replies: 6
    Last Post: 1st April 2009, 05:00
  4. QTreeView PARENT & CHILD
    By zeeb100 in forum Qt Programming
    Replies: 1
    Last Post: 10th February 2009, 14:53
  5. Connecting child and parent
    By maverick_pol in forum Qt Programming
    Replies: 17
    Last Post: 17th July 2007, 08:11

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.