CroCo
CroCo

Reputation: 5741

Close Dialogs once its main dialog is closed

I have Main Dialog which has some buttons. Each button will generate an independent dialog as follows:

void MainDialog::onAButtonClicked()
{
     Dialog *dial = new Dialog(pass some parameters);
     dial->show();
}

The problem with this approach is when the user closes the Main Dialog, the running independent dialog is not closed. I don't want this issue to occur. Some solutions suggest to override closeEvent and reject, I've tried them but these require me to create *dial as a member data of Main Dialog. This works but I don't want this approach because I need to delete this dialog once the user closes the window completely. I've tried to allocate some memory using new and delete object on close or reject events but the app hangs. What is the proper approach to solve this issue?

Upvotes: 1

Views: 70

Answers (1)

Michael
Michael

Reputation: 5335

connect(this,SIGNAL(finished(int)),dial,SLOT(close()));

or

connect(this,SIGNAL(rejected()),dial,SLOT(close()));

Upvotes: 3

Related Questions