From 9e168bc20aab1af6f5c279815a87a9df48df924f Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Tue, 22 Feb 2022 10:29:24 +0200 Subject: [PATCH] Merge bitcoin-core/gui#547: Override BitcoinApplication::event() to handle QEvent::Quit e7fc50681e99e3c726db2bc4d3d425ed8a0fc6b3 qt: Override BitcoinApplication::event() to handle QEvent::Quit (Hennadii Stepanov) Pull request description: bitcoin-core/gui#336 introduced a regression when termination requests from a platform are not handled properly. This PR fixes this regression. On macOS shutdown after clicking "Quit" in Dock icon menu, and during logout works again. Fixes bitcoin-core/gui#545. ACKs for top commit: RandyMcMillan: tACK e7fc50681e99e3c726db2bc4d3d425ed8a0fc6b3 Sjors: tACK e7fc50681e99e3c726db2bc4d3d425ed8a0fc6b3 (rebased on master) indeed fixes the crash described in #545 promag: Tested ACK e7fc50681e99e3c726db2bc4d3d425ed8a0fc6b3 on macOS 10.15 with Qt 5.15.2. Tree-SHA512: 236a483dc0828f22999469e133b8ac9f0b6267ec2a27004c3ebaa967689ddb972ea1fa90c1dd41f3bff3d17bf571a707babcef53bd79fd711fda98cfbf120131 --- src/qt/bitcoin.cpp | 10 ++++++++++ src/qt/bitcoin.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index ca528bfeda..39ca3b04b5 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -425,6 +425,16 @@ WId BitcoinApplication::getMainWinId() const return window->winId(); } +bool BitcoinApplication::event(QEvent* e) +{ + if (e->type() == QEvent::Quit) { + requestShutdown(); + return true; + } + + return QApplication::event(e); +} + static void SetupUIArgs(ArgsManager& argsman) { argsman.AddArg("-choosedatadir", strprintf(QObject::tr("Choose data directory on startup (default: %u)").toStdString(), DEFAULT_CHOOSE_DATADIR), ArgsManager::ALLOW_ANY, OptionsCategory::GUI); diff --git a/src/qt/bitcoin.h b/src/qt/bitcoin.h index fccaabcb45..72c42e274d 100644 --- a/src/qt/bitcoin.h +++ b/src/qt/bitcoin.h @@ -98,6 +98,9 @@ Q_SIGNALS: void splashFinished(); void windowShown(BitcoinGUI* window); +protected: + bool event(QEvent* e) override; + private: QThread *coreThread; interfaces::Node& m_node;