11/*
22 * Copyright 2012, 2013, 2014 Thomas Schöps
3- * Copyright 2012-2017 Kai Pastor
3+ * Copyright 2012-2018 Kai Pastor
44 *
55 * This file is part of OpenOrienteering.
66 *
@@ -255,10 +255,11 @@ void MainWindow::setController(MainWindowController* new_controller, bool has_fi
255255 createHelpMenu ();
256256
257257#if defined(Q_OS_MACOS)
258- // Disable all menu text heuristics, as a workaround for QTBUG-30812.
259- // Note that QAction::NoRole triggers QTBUG-29051,
260- // warnings in QCocoaMenuItem::sync() about menu items having
261- // "unsupported role QPlatformMenuItem::MenuRole(NoRole)".
258+ // Defeat Qt's menu text heuristic, as a workaround for QTBUG-30812.
259+ // Changing an action's menu role (to QAction::NoRole) after it was
260+ // added to the menu is unsupported and triggers crashes (#1077).
261+ // Instead, we defeat the heuristic by adding a zero width space at the
262+ // beginning and the end of the text of every action in the menus.
262263 const auto menubar_actions = menuBar ()->actions ();
263264 for (auto action : menubar_actions)
264265 {
@@ -267,15 +268,13 @@ void MainWindow::setController(MainWindowController* new_controller, bool has_fi
267268 const auto menu_actions = menu->actions ();
268269 for (auto action : menu_actions)
269270 {
270- if (action-> menuRole () == QAction::TextHeuristicRole)
271- action->setMenuRole (QAction::NoRole );
271+ static const auto zwsp = QString::fromUtf8 ( " \u200B " );
272+ action->setText (zwsp + action-> text () + zwsp );
272273 }
273274 }
274275 }
275276
276- // Probably related to QTBUG-62260.
277- // But even with Qt 5.9.3, the "Mapper" menu is not correct initially.
278- // (In Czech translation, the Settings menu is missing initially.)
277+ // Needed to activate the menu bar changes
279278 if (isVisible () && qApp->activeWindow () == this )
280279 {
281280 // Force a menu synchronisation,
0 commit comments