Destroy dialogs
-
I have a login dialog that shows up when my App loads , Thereafter i have a Main Window ,Once the user is validated i want to destroy the login dialog and show only the Main Window. My problem is i cant seem to be able to destroy the dialog - i have tried using LoginDialog::destroy() and LoginDialog::close() but neither works - all that happens is that the main windows shows up and the Login dialog still remains in behind the main window.
-
There is a number of approaches:
If you know beforehand that you're going to destroy it when it is closed:
@
Dialog *d = new Dialog(this);
d->setAttribute(WA_DeleteOnClose);
@If you are going to destroy it when finished:
@
Dialog *d = new Dialog(this);
connect(d, SIGNAL(accepted()), d, SLOT(deleteLater()));
@If you have something to validate in a slot:
@
if (stuffWasOk)
d->deleteLater();
@Of course these approaches all have their uses and drawbacks. By the way, deleteLater() is the correct function to use to get rid of the thing at all times. It tells the event loop to delete it. If you were to use delete directly, the event loop might try to deliver events to an object that no longer exists.