Skip to content

Instantly share code, notes, and snippets.

@martonmiklos
Created December 13, 2014 15:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martonmiklos/6e7d57be9570e5b5ef53 to your computer and use it in GitHub Desktop.
Save martonmiklos/6e7d57be9570e5b5ef53 to your computer and use it in GitHub Desktop.
Quit action for a Qt application with a Do not ask again checkbox
void MainWindow::on_actionQuit_triggered()
{
bool exit = false;
QSettings settings;
if (settings.value("quitWithoutPrompt").toBool()) {
exit = true;
} else {
QMessageBox quitQuestion;
QCheckBox checkBox;
checkBox.setText(tr("Do not ask again"));
quitQuestion.setCheckBox(&checkBox);
quitQuestion.setText(tr("Do you really want to exit this program?"));
quitQuestion.setWindowTitle(tr("Are you sure?"));
quitQuestion.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
quitQuestion.setDefaultButton(QMessageBox::No);
quitQuestion.exec();
if (quitQuestion.result() == QMessageBox::Yes) {
settings.setValue("quitWithoutPrompt", checkBox.isChecked());
exit = true;
}
}
if (exit)
QCoreApplication::quit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment