
Originally Posted by
Boy
deleteLater() can be used to delete an QDialog when it is closed?
It depends when you call it. But one way or the other deleting the widget causes it to close so the effect will be the same.
Am I correct that this is to be used so that all slots that are called when the dialog is closed are handled before the object becomes invalid?
Among other things, yes.
The way described by the topic starter:
object->deleteLater();
object->exec(); // stuff shown in dialog
// dialog closed, function ends and don't worry further, dialog will be deleted?
This will work but only because QDialog::exec() works in a special mode where it doesn't process deferred deletes.
The proper way to do it is either like so:
Dialog object;
object.exec();
Dialog object;
object.exec();
To copy to clipboard, switch view to plain text mode
... or ...
Dialog *object = new Dialog;
object->setAttribute(Qt::WA_DeleteOnClose);
object->exec();
Dialog *object = new Dialog;
object->setAttribute(Qt::WA_DeleteOnClose);
object->exec();
To copy to clipboard, switch view to plain text mode
Bookmarks