Hi,

I have a QMainWindow subclass with the attribute Qt::WA_DeleteOnClose set.

In some cases, I open a QDialog (and more exactly QWizard) that is a child of QMainWindow.

If the user interact with a particular QAction from the systray icon, I close the QMainWindow subclass programatically. The problem is after the call to the QMainWindow destructor, the control flow returned right after the QWizard exec call :

Qt Code:
  1. if(wizard)
  2. {
  3. if(wizard->exec())
  4. {
  5. if(wizard->field("displayListing").toBool())
  6. {
  7. setRootIndex(listingIndex);
  8. show();
  9. }
  10. }
  11.  
  12. delete wizard;
  13. wizard = 0;
  14. }
To copy to clipboard, switch view to plain text mode 

So in this particular case, delete wizard failed and I have a crash. Moreover, it is silly than some code class code could still be executed after the destruction of the object !!!

I have a solution (hope it could help) but I would like to know if there is a better way to deal with it.

Here is my solution by overidding the close() slot of the QMainWindow :

Qt Code:
  1. void MyWindow::close()
  2. {
  3. if(wizard)
  4. {
  5. closeRequested = true;
  6. wizard->reject();
  7. }
  8. else
  9. {
  10. QMainWindow::close();
  11. }
  12. }
To copy to clipboard, switch view to plain text mode 

So if the wizard pointer is not null, i set a member boolean variable to true and I programatically reject the dialog rather than propagating the close() call to the parent (QMainWindow) classe.

Then, the control returned right after the wizard->exec() call, I can safely destroy it and it test the boolean just after and do my close() call then.

Do you think there is a much cleaner solution ?