PDA

View Full Version : Does Qt destroy the widgets automatically or do I need to destroy them myself?



pir
24th June 2006, 20:34
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

jacek
24th June 2006, 20:55
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.


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