If your application uses QMainWindow , overload closeEvent() to display the dialog, and only call QMainWindow::closeEvent if the user clicked ok in your dialog box.
If your application uses QDialog , reload the accept() slot and only call QDialog::accept if the user clicked ok in your dialog box.
cppguy
source share