aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2021-11-05 12:27:45 +0100
committerEike Ziller <eike.ziller@qt.io>2021-11-08 13:05:16 +0000
commitf16589f96991d3801d2ec0a0068b5b231e1570fe (patch)
tree7f4e6512bbab1d882c4af2a013f546d0fece0ec1
parentaf8937f10fcbe1f210f1609fb1c927b675b83fd6 (diff)
Fix that Restart Now might not close Qt Creator
The call of QWidget::close() on the main window is blocked by Qt if there are modal windows open. First close/accept all currently open modal dialogs, then close the main window. Reverts a8bc9774f9c1948c603ec23daf47d4c4af67f23f which was specific to the Link with Qt functionality, and generalizes the code in MainWindow::exit(). Fixes: QTCREATORBUG-26525 Task-number: QTCREATORBUG-24098 Change-Id: I4c62f684cdfd749dfb3d3c18bd513b9fee10ddda Reviewed-by: Cristian Adam <cristian.adam@qt.io>
-rw-r--r--src/plugins/coreplugin/mainwindow.cpp25
-rw-r--r--src/plugins/qtsupport/qtoptionspage.cpp18
2 files changed, 28 insertions, 15 deletions
diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp
index bc8e438dcf..59ba9b08ab 100644
--- a/src/plugins/coreplugin/mainwindow.cpp
+++ b/src/plugins/coreplugin/mainwindow.cpp
@@ -92,6 +92,7 @@
#include <QStyleFactory>
#include <QToolButton>
#include <QUrl>
+#include <QWindow>
using namespace ExtensionSystem;
using namespace Utils;
@@ -939,6 +940,20 @@ void MainWindow::setFocusToEditor()
EditorManagerPrivate::doEscapeKeyFocusMoveMagic();
}
+static void acceptModalDialogs()
+{
+ const QWidgetList topLevels = QApplication::topLevelWidgets();
+ QList<QDialog *> dialogsToClose;
+ for (QWidget *topLevel : topLevels) {
+ if (auto dialog = qobject_cast<QDialog *>(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 0a8d55818a..b026363b34 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<QDialog *>(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