Created
December 13, 2014 15:21
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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