macOS: Track menu bar clicks for popup closing in QCocoaIntegration
A static member in QCocoaMenuBar relies on the app having at least one QCocoaMenuBar, and also stays around after the qGuiApp has gone away, potentially leading to a crash. As a drive-by, clarify the comment and variable name to point out that we're closing popups on _any_ native menu opening, not just menus in the main menu bar (NSApp.mainMenu). Pick-to: 6.7 6.5 Change-Id: Ib14919e317d70e4c76f3d89c78331edb958bf048 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit daad2b28fdb884e6d796ab024bcb962155cf5534) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
b694c58d5e
commit
9758c1556c
@ -119,6 +119,8 @@ private:
|
||||
#endif
|
||||
|
||||
QCocoaWindowManager m_windowManager;
|
||||
|
||||
QMacNotificationObserver m_menuTrackingObserver;
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(QCocoaIntegration::Options)
|
||||
|
@ -168,6 +168,12 @@ QCocoaIntegration::QCocoaIntegration(const QStringList ¶mList)
|
||||
|
||||
connect(qGuiApp, &QGuiApplication::focusWindowChanged,
|
||||
this, &QCocoaIntegration::focusWindowChanged);
|
||||
|
||||
// Opening of a native menu should close all popup windows
|
||||
m_menuTrackingObserver = QMacNotificationObserver(nil,
|
||||
NSMenuDidBeginTrackingNotification, ^{
|
||||
QGuiApplicationPrivate::instance()->closeAllPopups();
|
||||
});
|
||||
}
|
||||
|
||||
QCocoaIntegration::~QCocoaIntegration()
|
||||
|
@ -25,11 +25,6 @@ QCocoaMenuBar::QCocoaMenuBar()
|
||||
{
|
||||
static_menubars.append(this);
|
||||
|
||||
// clicks into the menu bar should close all popup windows
|
||||
static QMacNotificationObserver menuBarClickObserver(nil, NSMenuDidBeginTrackingNotification, ^{
|
||||
QGuiApplicationPrivate::instance()->closeAllPopups();
|
||||
});
|
||||
|
||||
m_nativeMenu = [[NSMenu alloc] init];
|
||||
qCDebug(lcQpaMenus) << "Constructed" << this << "with" << m_nativeMenu;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user