My application shows an icon in system tray which allows user to quit the application. Sometimes, my app will popup a dialog to let user verify.

Qt Code:
  1. void MyWidget::showWarning()
  2. {
  3. QDialog dialog;
  4. ...
  5. ...
  6. int result = dialog.exec();
  7. if(result == QDialog::Accepted)
  8. {
  9. ...
  10. }
  11. }
To copy to clipboard, switch view to plain text mode 

The problem is, if the local QDialog object is executing when user quits the app.MyWidget will be deleted before the line
Qt Code:
  1. if(result == QDialog::Accepted)
To copy to clipboard, switch view to plain text mode 
is called, which makes the app crash.

So, how do I safely finish the QDialog when the user quits the app?