From 7f2f38d48b58b6b1ef90198bf2d03422826a5b08 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Wed, 25 Nov 2009 15:38:45 +0100 Subject: Cocoa: 'Quit' in menu bar does not work If you have two window, each with its own menu bar that has a 'Quit' action, we reuse the quit menu item when switching between the windows. Now, it we deleteLater one of the menu bars, the new menubar will update the 'Quit' item just before deleteLater will come along and remote the update again. This patch will fix this. Task-number: QTBUG-4684 Reviewed-by: Prasanth --- src/gui/kernel/qcocoamenuloader_mac.mm | 7 ++++++- src/gui/widgets/qmenu_mac.mm | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/gui/kernel/qcocoamenuloader_mac.mm b/src/gui/kernel/qcocoamenuloader_mac.mm index 9ab077f..990571d 100644 --- a/src/gui/kernel/qcocoamenuloader_mac.mm +++ b/src/gui/kernel/qcocoamenuloader_mac.mm @@ -76,9 +76,14 @@ QT_USE_NAMESPACE - (void)ensureAppMenuInMenu:(NSMenu *)menu { + // The application menu is the menu in the menu bar that contains the + // 'Quit' item. When changing menu bar (e.g when swithing between + // windows with different menu bars), we never recreate this menu, but + // instead pull it out the current menu bar and place into the new one: NSMenu *mainMenu = [NSApp mainMenu]; if ([NSApp mainMenu] == menu) - return; // nothing to do! + return; // nothing to do (menu is the current menu bar)! + #ifndef QT_NAMESPACE Q_ASSERT(mainMenu); #endif diff --git a/src/gui/widgets/qmenu_mac.mm b/src/gui/widgets/qmenu_mac.mm index 9510cc6..8b371e5 100644 --- a/src/gui/widgets/qmenu_mac.mm +++ b/src/gui/widgets/qmenu_mac.mm @@ -774,8 +774,12 @@ QMacMenuAction::~QMacMenuAction() && menuItem != [getMenuLoader() quitMenuItem]) { [menuItem setHidden:YES]; } + // Only clear the tag if it points to this action. Since items like + // 'Quit' is being reused, we sometimes end up redirecting the item + // before deleting the assosiated action. + if (action.data() == reinterpret_cast([menuItem tag])) + [menuItem setTag:nil]; } - [menuItem setTag:nil]; [menuItem release]; #endif } -- cgit v0.12