PDA

View Full Version : Qt::WA_DeleteOnClose



merlvingian
22nd November 2006, 17:37
Looking for confirmation on this attribute and garbage collection. If I do the following:



QWidget *Qw = new QWidget();

Qw->setAttribute(Qt::WA_DeleteOnClose, true);
qDebug() << testAttribute(Qt::WA_DeleteOnClose); // paranoid confirmation

Qw->close();

// At this point I can still access Qw without any errors
qDebug() << Qw->baseSize(); // pick any access function


Now this code never crashes for me, my guess would be that garbage collection happens when time permits and the post close access is playing Russian roulette.

Is this the correct assumption?

jpn
22nd November 2006, 18:06
It will be deleted as soon as the control returns to the event loop. This is done by QObject::deleteLater().

merlvingian
22nd November 2006, 18:28
Along the same line of simplistic questions, if I have a signal/slot connection to a widget that is removed with a Qt::WA_DeleteOnClose is the connection automatically removed or would I have to manually disconnect it before the call to close?

There should be no way to emit a signal since the widget is deleted but if it has slots connected from other widgets my guess is they would have to be disconnected to keep things tidy.

jpn
22nd November 2006, 18:38
Yes, connections are cleaned up when any QObject is destroyed. See QObject::~QObject() (http://doc.trolltech.com/4.2/qobject.html#dtor.QObject).