From d2864ffcc0dc91a64bb3b5d3cb649852f8a6b271 Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 28 Aug 2012 12:42:42 +0100 Subject: [PATCH] Fix missing cleanup of native Cocoa menus. QCocoaMenu was missing a destructor to release various native resources, and this causes issues with pop-up menus when the Qt peers are recycled on successive shows of the same menu. Task-number: QTBUG-27022 Change-Id: I3cdf979804358ce10fe8a87c9e2c90419c6e0b48 Reviewed-by: Christoph Schleifenbaum Reviewed-by: Sean Harmer Reviewed-by: Friedemann Kleint --- src/plugins/platforms/cocoa/qcocoamenu.h | 1 + src/plugins/platforms/cocoa/qcocoamenu.mm | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/plugins/platforms/cocoa/qcocoamenu.h b/src/plugins/platforms/cocoa/qcocoamenu.h index 479d4b53c2..c523b27076 100644 --- a/src/plugins/platforms/cocoa/qcocoamenu.h +++ b/src/plugins/platforms/cocoa/qcocoamenu.h @@ -59,6 +59,7 @@ class QCocoaMenu : public QPlatformMenu { public: QCocoaMenu(); + ~QCocoaMenu(); inline virtual void setTag(quintptr tag) { m_tag = tag; } diff --git a/src/plugins/platforms/cocoa/qcocoamenu.mm b/src/plugins/platforms/cocoa/qcocoamenu.mm index 951bbb90c3..a39263ecab 100644 --- a/src/plugins/platforms/cocoa/qcocoamenu.mm +++ b/src/plugins/platforms/cocoa/qcocoamenu.mm @@ -107,6 +107,14 @@ QCocoaMenu::QCocoaMenu() : [m_nativeItem setSubmenu:m_nativeMenu]; } +QCocoaMenu::~QCocoaMenu() +{ + [m_nativeItem setSubmenu:nil]; + [m_nativeMenu release]; + [m_delegate release]; + [m_nativeItem release]; +} + void QCocoaMenu::setText(const QString &text) { QCocoaAutoReleasePool pool; @@ -142,6 +150,7 @@ void QCocoaMenu::insertNative(QCocoaMenuItem *item, QCocoaMenuItem *beforeItem) if (item->isMerged()) return; + Q_ASSERT([item->nsItem() menu] == NULL); // if the item we're inserting before is merged, skip along until // we find a non-merged real item to insert ahead of. while (beforeItem && beforeItem->isMerged()) { @@ -163,6 +172,7 @@ void QCocoaMenu::removeMenuItem(QPlatformMenuItem *menuItem) Q_ASSERT(m_menuItems.contains(cocoaItem)); m_menuItems.removeOne(cocoaItem); if (!cocoaItem->isMerged()) { + Q_ASSERT(m_nativeMenu == [cocoaItem->nsItem() menu]); [m_nativeMenu removeItem: cocoaItem->nsItem()]; } }