QCocoaMenu: Don't rely on tags when we can get the actual NSMenuItem

-[NSMenu itemWithTag:] clearly states that it'll return the first
item with that tag. Furthermore, when and item has been synced more
than once, it could be that more than one such item exists in the
same menu (e.g. lately changing the role of Edit->Copy).

Change-Id: I95a4f0a151659ae273ba03a3cab4a720b781fc3a
Task-number: QTBUG-57404
Reviewed-by: Jake Petroules <jake.petroules@qt.io>
This commit is contained in:
Gabriel de Dietrich 2016-12-05 14:38:12 -08:00 committed by Jani Heikkinen
parent b2f78b796b
commit 093e1111ef
2 changed files with 3 additions and 5 deletions

View File

@ -419,9 +419,8 @@ void QCocoaMenu::syncMenuItem(QPlatformMenuItem *menuItem)
return; return;
} }
bool wasMerged = cocoaItem->isMerged(); const bool wasMerged = cocoaItem->isMerged();
NSMenu *oldMenu = wasMerged ? [[QCocoaMenuLoader sharedMenuLoader] applicationMenu] : m_nativeMenu; NSMenuItem *oldItem = cocoaItem->nsItem();
NSMenuItem *oldItem = [oldMenu itemWithTag:(NSInteger) cocoaItem];
if (cocoaItem->sync() != oldItem) { if (cocoaItem->sync() != oldItem) {
// native item was changed for some reason // native item was changed for some reason

View File

@ -1560,11 +1560,10 @@ void tst_QMenuBar::QTBUG_57404_existingMenuItemException()
QVERIFY(QTest::qWaitForWindowExposed(&mw2)); QVERIFY(QTest::qWaitForWindowExposed(&mw2));
QTest::qWait(100); QTest::qWait(100);
QTest::ignoreMessage(QtWarningMsg, "Menu item \"&Copy\" already in menu \"Edit\"");
mw2.close(); mw2.close();
mw1.activateWindow(); mw1.activateWindow();
QTest::qWait(100); QTest::qWait(100);
// No crash, all fine. // No crash, all fine. Ideally, there should be only one warning.
} }
#endif // Q_OS_MACOS #endif // Q_OS_MACOS