Results 1 to 2 of 2

Thread: Does Qt destroy the widgets automatically or do I need to destroy them myself?

  1. #1
    Join Date
    May 2006
    Location
    Stockholm, Sweden
    Posts
    81
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Does Qt destroy the widgets automatically or do I need to destroy them myself?

    Hi!

    I am very confused about what a parent means in Qt. I looked at Qt's homepage, I'm especially confused about destruction of widgets. Does parenting have something to do with it?

    If I have a widget A and creates a widget B which I set as a child to A, what does this mean besides layout matters? Does it mean that B's destructor is called automatically by Qt when A is destroyed? Does Qt handle all destruction of the GUI? If I create a window with no parent, is this not destroyed by Qt?
    Where can I read about this?

    It would be nice if someone could tell me where I can read about destruction, since I have a lot of questions and it maybe is best if I can read about it.

    pir

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Does Qt destroy the widgets automatically or do I need to destroy them myself?

    Quote Originally Posted by pir
    Does it mean that B's destructor is called automatically by Qt when A is destroyed?
    When QObject is being destroyed, it destroys all of its children.

    Since every QWidget is a QObject, all widgets destroy their children automatically.

    Quote Originally Posted by pir
    Does Qt handle all destruction of the GUI? If I create a window with no parent, is this not destroyed by Qt?
    No, you have to destroy all widgets without parents yourself (unless you have set the Qt::WA_DeleteOnClose attribute).

    http://doc.trolltech.com/4.1/objecttrees.html
    Last edited by jacek; 24th June 2006 at 20:59.

Similar Threads

  1. Creating Widgets
    By hylke in forum Qt Programming
    Replies: 2
    Last Post: 5th February 2006, 08:37

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.