Check if there is an old item before removing it
authorAndy Shaw <andy.shaw@digia.com>
Wed, 10 Oct 2012 09:23:31 +0000 (11:23 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 16 Oct 2012 13:29:15 +0000 (15:29 +0200)
If something had changed with the menu item before it had actually been
originally added to the native menu then this would crash when trying
to remove a null item from the native menu.  This prevents that from
happening.

Change-Id: I8d78b5504759225364d5fd051a23c8d6dbd7d1eb
Reviewed-by: James Turner <james.turner@kdab.com>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
src/plugins/platforms/cocoa/qcocoamenu.mm

index e4baaab..4d35b32 100644 (file)
@@ -218,10 +218,9 @@ void QCocoaMenu::syncMenuItem(QPlatformMenuItem *menuItem)
     NSMenuItem *oldItem = [m_nativeMenu itemWithTag:(NSInteger) cocoaItem];
 
     if (cocoaItem->sync() != oldItem) {
-    // native item was changed for some reason
-        if (!wasMerged) {
+        // native item was changed for some reason
+        if (!wasMerged && oldItem)
             [m_nativeMenu removeItem:oldItem];
-        }
 
         QCocoaMenuItem* beforeItem = itemOrNull(m_menuItems.indexOf(cocoaItem) + 1);
         insertNative(cocoaItem, beforeItem);