summaryrefslogtreecommitdiffstats
path: root/src/gui/widgets/qmenu_mac.mm
diff options
context:
space:
mode:
authorPrasanth Ullattil <prasanth.ulattil@nokia.com>2009-09-18 13:38:26 +0200
committerPrasanth Ullattil <prasanth.ulattil@nokia.com>2009-09-18 13:38:26 +0200
commitfaec535829a0e454a6784b0c5c37cb63e7da8f73 (patch)
treebf9f4c0103c1443d559d7ddd9bb7a0b15ed03a53 /src/gui/widgets/qmenu_mac.mm
parent39ec3f66db65684b32b8c5f35311d6045135c4d0 (diff)
Application crashes when a menu is inserted twice on a menubar (Cocoa).
Cocoa does not allow NSMenu to have multiple supermenu's. If a menu is added again as submenu, Qt will now disable the menu item or the menu will not be added at all if it is added again to the menubar. Task-number: 258822 Reviewed-by: MortenS
Diffstat (limited to 'src/gui/widgets/qmenu_mac.mm')
-rw-r--r--src/gui/widgets/qmenu_mac.mm15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/gui/widgets/qmenu_mac.mm b/src/gui/widgets/qmenu_mac.mm
index 264d6d3c2e..354161da9e 100644
--- a/src/gui/widgets/qmenu_mac.mm
+++ b/src/gui/widgets/qmenu_mac.mm
@@ -1412,7 +1412,15 @@ QMenuPrivate::QMacMenuPrivate::syncAction(QMacMenuAction *action)
GetMenuItemProperty(action->menu, 0, kMenuCreatorQt, kMenuPropertyQWidget, sizeof(caused), 0, &caused);
SetMenuItemProperty(data.submenuHandle, 0, kMenuCreatorQt, kMenuPropertyCausedQWidget, sizeof(caused), &caused);
#else
- [item setSubmenu:static_cast<NSMenu *>(action->action->menu()->macMenu())];
+ NSMenu *subMenu = static_cast<NSMenu *>(action->action->menu()->macMenu());
+ if ([subMenu supermenu] != nil) {
+ // The menu is already a sub-menu of another one. Cocoa will throw an exception,
+ // in such cases. For the time being, a new QMenu with same set of actions is the
+ // only workaround.
+ action->action->setEnabled(false);
+ } else {
+ [item setSubmenu:subMenu];
+ }
#endif
} else { //respect some other items
#ifndef QT_MAC_USE_COCOA
@@ -1678,7 +1686,10 @@ QMenuBarPrivate::QMacMenuBarPrivate::syncAction(QMacMenuAction *action)
GetMenuItemProperty(action->menu, 0, kMenuCreatorQt, kMenuPropertyQWidget, sizeof(caused), 0, &caused);
SetMenuItemProperty(submenu, 0, kMenuCreatorQt, kMenuPropertyCausedQWidget, sizeof(caused), &caused);
#else
- [item setSubmenu:submenu];
+ if ([submenu supermenu] != nil)
+ return;
+ else
+ [item setSubmenu:submenu];
#endif
}
#ifndef QT_MAC_USE_COCOA