Skip to content

Commit fb01af6

Browse files
committed
Merge bitcoin-core#680: Fixes MacOS 13 segfault by preventing certain notifications after main window is destroyed
8a5014c Fixes bitcoin#26490 by preventing notifications (John Moffett) Pull request description: This is a PR to address bitcoin/bitcoin#26490 The menu bar currently subscribes to window focus change notifications to enable or disable certain menu options in response to the window status. Notifications are automatically unsubscribed (disconnected in Qt parlance) if the sender is deleted -- in this case, the sender is the QTApplication object (`qApp`). However, MacOS 13 sends a window focus change notification *after* the main window has been destroyed but *before* `qApp` has been fully destroyed. Since the menu bar is deleted in the main window's destructor, it no longer exists when it receives these notifications (in two different places via lambda expressions). The solution is to pass the main window (`this`) as context when subscribing to the notifications. In this [overloaded version](https://doc.qt.io/qt-5/qobject.html#connect-1) of `connect`, Qt automatically unsubscribes to notifications if the sender OR context (here the main window object) is destroyed. Since the spurious notifications are sent after the main window object is destroyed, this change prevents them from being sent. Tested on Mac OS 13 and 12 only. ACKs for top commit: hebasto: ACK 8a5014c Tree-SHA512: 3dff0a252fe0e93dd68cf5503135ecf6a72bcf385ba38407d6021ab77cca323f8bbe58aeca90ec124aa2a22ab9d35b706946179ac3b5d171c96a7010de51a090
2 parents 82fe672 + 8a5014c commit fb01af6

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/qt/bitcoingui.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ void BitcoinGUI::createMenuBar()
512512
connect(minimize_action, &QAction::triggered, [] {
513513
QApplication::activeWindow()->showMinimized();
514514
});
515-
connect(qApp, &QApplication::focusWindowChanged, [minimize_action] (QWindow* window) {
515+
connect(qApp, &QApplication::focusWindowChanged, this, [minimize_action] (QWindow* window) {
516516
minimize_action->setEnabled(window != nullptr && (window->flags() & Qt::Dialog) != Qt::Dialog && window->windowState() != Qt::WindowMinimized);
517517
});
518518

@@ -527,7 +527,7 @@ void BitcoinGUI::createMenuBar()
527527
}
528528
});
529529

530-
connect(qApp, &QApplication::focusWindowChanged, [zoom_action] (QWindow* window) {
530+
connect(qApp, &QApplication::focusWindowChanged, this, [zoom_action] (QWindow* window) {
531531
zoom_action->setEnabled(window != nullptr);
532532
});
533533
#endif

0 commit comments

Comments
 (0)