diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp index bc8e438dcfc..59ba9b08abc 100644 --- a/src/plugins/coreplugin/mainwindow.cpp +++ b/src/plugins/coreplugin/mainwindow.cpp @@ -92,6 +92,7 @@ #include #include #include +#include using namespace ExtensionSystem; using namespace Utils; @@ -939,6 +940,20 @@ void MainWindow::setFocusToEditor() EditorManagerPrivate::doEscapeKeyFocusMoveMagic(); } +static void acceptModalDialogs() +{ + const QWidgetList topLevels = QApplication::topLevelWidgets(); + QList dialogsToClose; + for (QWidget *topLevel : topLevels) { + if (auto dialog = qobject_cast(topLevel)) { + if (dialog->isModal()) + dialogsToClose.append(dialog); + } + } + for (QDialog *dialog : dialogsToClose) + dialog->accept(); +} + void MainWindow::exit() { // this function is most likely called from a user action @@ -946,7 +961,15 @@ void MainWindow::exit() // since on close we are going to delete everything // so to prevent the deleting of that object we // just append it - QMetaObject::invokeMethod(this, &QWidget::close, Qt::QueuedConnection); + QMetaObject::invokeMethod( + this, + [this] { + // Modal dialogs block the close event. So close them, in case this was triggered from + // a RestartDialog in the settings dialog. + acceptModalDialogs(); + close(); + }, + Qt::QueuedConnection); } void MainWindow::openFileWith() diff --git a/src/plugins/qtsupport/qtoptionspage.cpp b/src/plugins/qtsupport/qtoptionspage.cpp index 0a8d55818a4..b026363b34a 100644 --- a/src/plugins/qtsupport/qtoptionspage.cpp +++ b/src/plugins/qtsupport/qtoptionspage.cpp @@ -177,7 +177,7 @@ public: QtOptionsPageWidget(); ~QtOptionsPageWidget(); - static bool linkWithQt(); + static void linkWithQt(); private: void apply() final; @@ -857,16 +857,7 @@ void QtOptionsPageWidget::setupLinkWithQtButton() QString tip; canLinkWithQt(&tip); m_ui.linkWithQtButton->setToolTip(tip); - connect(m_ui.linkWithQtButton, &QPushButton::clicked, this, [this] { - if (linkWithQt()) { - QWidget *w = window(); - // close options dialog - if (QDialog *dialog = qobject_cast(w)) - dialog->accept(); - else - window()->close(); - } - }); + connect(m_ui.linkWithQtButton, &QPushButton::clicked, this, &QtOptionsPage::linkWithQt); } void QtOptionsPageWidget::updateCurrentQtName() @@ -959,7 +950,7 @@ static FilePath defaultQtInstallationPath() return FileUtils::homePath() / "Qt"; } -bool QtOptionsPageWidget::linkWithQt() +void QtOptionsPageWidget::linkWithQt() { const QString title = tr("Choose Qt Installation"); const QString restartText = tr("The change will take effect after restart."); @@ -1028,9 +1019,8 @@ bool QtOptionsPageWidget::linkWithQt() } if (askForRestart) { Core::RestartDialog restartDialog(Core::ICore::dialogParent(), restartText); - return restartDialog.exec() == QDialog::Accepted; + restartDialog.exec(); } - return false; } // QtOptionsPage