From 939b7bfe66221975d3a12a6d0a6dd14d9ad04344 Mon Sep 17 00:00:00 2001
From: Gabriel de Dietrich <gabriel.dedietrich@qt.io>
Date: Mon, 2 May 2016 16:49:44 -0700
Subject: [PATCH] QCocoaMenuBar: set the native item's title

Or, "Give Cocoa a Chance to do its Magic"

Some menubar items, like the "Edit" menu, get extra items added
at some point by Cocoa. Evidence points out to those extra items
being added right after the NSMenu holding the menubar is set as
the current menubar. At that point, both the child NSMenu and its
NSMenuItem (the entry in the menubar) must have their title set.

Therefore, we must set the menubar native item's title before
QCocoaMenuBar::updateMenuBarImmediately() sets the main menu.

Task-number: QTBUG-53085
Change-Id: Idd775cf0e3485739f38363a84cfed8d2db9cb662
Reviewed-by: Jake Petroules <jake.petroules@qt.io>
Reviewed-by: Liang Qi <liang.qi@qt.io>
Reviewed-by: Marko Kangas <marko.kangas@theqtcompany.com>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com>
---
 src/plugins/platforms/cocoa/qcocoamenubar.mm | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/plugins/platforms/cocoa/qcocoamenubar.mm b/src/plugins/platforms/cocoa/qcocoamenubar.mm
index ac48a0e3101..a534d2064e8 100644
--- a/src/plugins/platforms/cocoa/qcocoamenubar.mm
+++ b/src/plugins/platforms/cocoa/qcocoamenubar.mm
@@ -173,7 +173,9 @@ void QCocoaMenuBar::syncMenu(QPlatformMenu *menu)
             }
     }
 
-    nativeItemForMenu(cocoaMenu).hidden = shouldHide;
+    NSMenuItem *nativeMenuItem = nativeItemForMenu(cocoaMenu);
+    nativeMenuItem.title = cocoaMenu->nsMenu().title;
+    nativeMenuItem.hidden = shouldHide;
 }
 
 NSMenuItem *QCocoaMenuBar::nativeItemForMenu(QCocoaMenu *menu) const
-- 
GitLab