Qt - 如果QInputDialog取消,关闭应用程序

时间:2017-06-06 12:49:48

标签: c++ qt

我试图制作一个棋盘游戏,程序所做的第一件事就是要求难度。如果用户按下取消,我想关闭整个程序。我正在做:

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();
    }
}

然而,这不起作用:如果我按下取消,仍然会出现一个空白窗口。为什么会发生这种情况?如果按下取消,如何关闭窗口/程序?

0 个答案:

没有答案