diff --git a/src/plugins/platforms/cocoa/qcocoamenu.mm b/src/plugins/platforms/cocoa/qcocoamenu.mm index e5681c0894..d7f0efe86c 100644 --- a/src/plugins/platforms/cocoa/qcocoamenu.mm +++ b/src/plugins/platforms/cocoa/qcocoamenu.mm @@ -328,6 +328,13 @@ void QCocoaMenu::insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem * } insertNative(cocoaItem, beforeItem); + + // Empty menus on a menubar are hidden by default. If the menu gets + // added to the menubar before it contains any item, we need to sync. + if (isVisible() && attachedItem().hidden) { + if (auto *mb = qobject_cast(menuParent())) + mb->syncMenu(this); + } } void QCocoaMenu::insertNative(QCocoaMenuItem *item, QCocoaMenuItem *beforeItem) diff --git a/src/plugins/platforms/cocoa/qcocoamenubar.mm b/src/plugins/platforms/cocoa/qcocoamenubar.mm index 4cdf004dd1..70fcb40774 100644 --- a/src/plugins/platforms/cocoa/qcocoamenubar.mm +++ b/src/plugins/platforms/cocoa/qcocoamenubar.mm @@ -370,7 +370,7 @@ void QCocoaMenuBar::updateMenuBarImmediately() QCocoaMenuLoader *loader = [QCocoaMenuLoader sharedMenuLoader]; [loader ensureAppMenuInMenu:mb->nsMenu()]; - NSMutableSet *mergedItems = [[NSMutableSet setWithCapacity:0] retain]; + NSMutableSet *mergedItems = [[NSMutableSet setWithCapacity:mb->merged().count()] retain]; foreach (QCocoaMenuItem *m, mb->merged()) { [mergedItems addObject:m->nsItem()]; m->syncMerged();