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 <christoph.schleifenbaum@kdab.com>
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
This commit is contained in:
James Turner 2012-08-28 12:42:42 +01:00 committed by Qt by Nokia
parent 823da2d308
commit d2864ffcc0
2 changed files with 11 additions and 0 deletions

View File

@ -59,6 +59,7 @@ class QCocoaMenu : public QPlatformMenu
{
public:
QCocoaMenu();
~QCocoaMenu();
inline virtual void setTag(quintptr tag)
{ m_tag = tag; }

View File

@ -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()];
}
}