I'm trying to make a board game where the first thing the program does is it asks for the difficulty. I'd like to close the whole program if the user presses cancel. I'm doing:
GameWindow::GameWindow(QWidget *parent)
: QWidget(parent)
{
QList<QString> difficultyChooser;
difficultyChooser << "Easy" << "Medium" << "Hard";
QInputDialog *dialog = new QInputDialog();
bool accepted;
QString item = dialog->getItem(0, "New game", "Choose difficulty!", difficultyChooser, 0, false, &accepted);
if (accepted && !item.isEmpty()) {
if(item == "Easy") {
_gameManager->difficulty = Easy;
} else if (item == "Medium") {
_gameManager->difficulty = Medium;
} else {
_gameManager->difficulty = Hard;
}
//setup window etc
} else {
this->close();
QApplication::quit();
}
}
This however, doesn't work: If I press Cancel, a blank window still appears. Why does this happen and how can I close the window/program if Cancel is pressed?