diff options
author | Prasanth Ullattil <prasanth.ulattil@nokia.com> | 2009-09-18 11:38:26 (GMT) |
---|---|---|
committer | Jason McDonald <jason.mcdonald@nokia.com> | 2009-09-21 04:49:41 (GMT) |
commit | 06ce0acefbf8890e4d8ffd56f6ab9c51f8446e15 (patch) | |
tree | 507f26fcc080774c5295b9ee1cac2b59eb7487ff | |
parent | 8d64d6be894116acec555cf751a6af288b76e3b8 (diff) | |
download | Qt-06ce0acefbf8890e4d8ffd56f6ab9c51f8446e15.zip Qt-06ce0acefbf8890e4d8ffd56f6ab9c51f8446e15.tar.gz Qt-06ce0acefbf8890e4d8ffd56f6ab9c51f8446e15.tar.bz2 |
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
(cherry picked from commit faec535829a0e454a6784b0c5c37cb63e7da8f73)
-rw-r--r-- | src/gui/widgets/qmenu.cpp | 5 | ||||
-rw-r--r-- | src/gui/widgets/qmenu_mac.mm | 15 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp index 688b23d..7793b80 100644 --- a/src/gui/widgets/qmenu.cpp +++ b/src/gui/widgets/qmenu.cpp @@ -1302,6 +1302,11 @@ void QMenu::initStyleOption(QStyleOptionMenuItem *option, const QAction *action) do not support the signals: aboutToHide (), aboutToShow () and hovered (). It is not possible to display an icon in a native menu on Windows Mobile. + \section1 QMenu on Mac OS X with Qt build against Cocoa + + QMenu can be inserted only once in a menu/menubar. Subsequent insertions will + have no effect or will result in a disabled menu item. + See the \l{mainwindows/menus}{Menus} example for an example of how to use QMenuBar and QMenu in your application. diff --git a/src/gui/widgets/qmenu_mac.mm b/src/gui/widgets/qmenu_mac.mm index c19175f..c1078c3 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 |