|
54 | 54 | #include <QThread> |
55 | 55 | #include <QTimer> |
56 | 56 | #include <QTranslator> |
| 57 | +#include <QWindow> |
57 | 58 |
|
58 | 59 | #if defined(QT_STATICPLUGIN) |
59 | 60 | #include <QtPlugin> |
@@ -259,6 +260,7 @@ void BitcoinApplication::createOptionsModel(bool resetSettings) |
259 | 260 | void BitcoinApplication::createWindow(const NetworkStyle *networkStyle) |
260 | 261 | { |
261 | 262 | window = new BitcoinGUI(node(), platformStyle, networkStyle, nullptr); |
| 263 | + connect(window, &BitcoinGUI::quitClicked, this, &BitcoinApplication::requestShutdown); |
262 | 264 |
|
263 | 265 | pollShutdownTimer = new QTimer(window); |
264 | 266 | connect(pollShutdownTimer, &QTimer::timeout, window, &BitcoinGUI::detectShutdown); |
@@ -333,14 +335,18 @@ void BitcoinApplication::requestInitialize() |
333 | 335 |
|
334 | 336 | void BitcoinApplication::requestShutdown() |
335 | 337 | { |
| 338 | + for (const auto w : QGuiApplication::topLevelWindows()) { |
| 339 | + w->hide(); |
| 340 | + } |
| 341 | + |
336 | 342 | // Show a simple window indicating shutdown status |
337 | 343 | // Do this first as some of the steps may take some time below, |
338 | 344 | // for example the RPC console may still be executing a command. |
339 | 345 | shutdownWindow.reset(ShutdownWindow::showShutdownWindow(window)); |
340 | 346 |
|
341 | 347 | qDebug() << __func__ << ": Requesting shutdown"; |
342 | 348 | startThread(); |
343 | | - window->hide(); |
| 349 | + |
344 | 350 | // Must disconnect node signals otherwise current thread can deadlock since |
345 | 351 | // no event loop is running. |
346 | 352 | window->unsubscribeFromCoreSignals(); |
@@ -406,13 +412,13 @@ void BitcoinApplication::initializeResult(bool success, interfaces::BlockAndHead |
406 | 412 | pollShutdownTimer->start(200); |
407 | 413 | } else { |
408 | 414 | Q_EMIT splashFinished(); // Make sure splash screen doesn't stick around during shutdown |
409 | | - quit(); // Exit first main loop invocation |
| 415 | + requestShutdown(); |
410 | 416 | } |
411 | 417 | } |
412 | 418 |
|
413 | 419 | void BitcoinApplication::shutdownResult() |
414 | 420 | { |
415 | | - quit(); // Exit second main loop invocation after shutdown finished |
| 421 | + quit(); |
416 | 422 | } |
417 | 423 |
|
418 | 424 | void BitcoinApplication::handleRunawayException(const QString &message) |
@@ -635,8 +641,6 @@ int GuiMain(int argc, char* argv[]) |
635 | 641 | #if defined(Q_OS_WIN) |
636 | 642 | WinShutdownMonitor::registerShutdownBlockReason(QObject::tr("%1 didn't yet exit safely…").arg(PACKAGE_NAME), (HWND)app.getMainWinId()); |
637 | 643 | #endif |
638 | | - app.exec(); |
639 | | - app.requestShutdown(); |
640 | 644 | app.exec(); |
641 | 645 | rv = app.getReturnValue(); |
642 | 646 | } else { |
|
0 commit comments