From 063997f44ffc1b6650ef6d67832674d5511fdb63 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 14 Oct 2016 16:16:02 +0200 Subject: QMenu: don't force platform instance creation on construction There's a conflict between QGtk3Menu and QDbusPlatformMenuBar. The problem is that on Unity the type of the platform menu instance must be different depending on whether the menu is in the global menubar or a standalone context menu. Since QMenu creates a platform menu instance at construction time, it does not yet know whether it will be added into a menubar. QMenuBar checks that the QMenu already has a platform menu instance, and passes it to the platform menubar. As a result, a QGtk3Menu instance is passed to QDbusPlatformMenuBar. Currently, a standalone QMenu does not use the native platform menu instance. Only menus that are added to a QMenuBar do. Therefore we don't need to create the platform instance when QMenu is constructed, but only after it is added to QMenuBar. The platform menu instance creation is implemented in QMenuBarPrivate::getPlatformMenu(), and QMenu::setPlatformMenu() calls syncPlatformMenu() to take care of syncing the QMenu properties and actions to the new platform menu instance. The macOS-specific methods QMenu::toNSMenu() and QMenu::setAsDockMenu() rely on the platform menu instance, and must therefore create it on demand. This is a hot fix for the release blocker, not a long term solution. In the future, if standalone QMenus are made to use native platform menu instances, the instance must be created lazily when the menu is about to be made visible. Task-number: QTBUG-56526 Change-Id: I044933cabb1639406fe47908dfc4b1903af214d1 Reviewed-by: Dmitry Shachnev Reviewed-by: Lars Knoll --- .../auto/widgets/widgets/qmenubar/tst_qmenubar.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests') diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp index ca58dc1247..475ce2a317 100644 --- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp +++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp @@ -131,6 +131,8 @@ private slots: void cornerWidgets(); void taskQTBUG53205_crashReparentNested(); + void platformMenu(); + protected slots: void onSimpleActivated( QAction*); void onComplexActionTriggered(); @@ -1487,6 +1489,25 @@ void tst_QMenuBar::taskQTBUG53205_crashReparentNested() testMenus.actions[0]->trigger(); } +// QTBUG-56526 +void tst_QMenuBar::platformMenu() +{ + QMenuBar menuBar; + QPlatformMenuBar *platformMenuBar = menuBar.platformMenuBar(); + if (!platformMenuBar) + QSKIP("No platform menubar implementation available on this platform."); + + // QMenu must not create a platform menu instance at creation time, because + // on Unity the type of the platform menu instance must be different (QGtk3Menu + // vs. QDbusPlatformMenu) depending on whether the menu is in the global menubar + // or a standalone context menu. + QMenu *menu = new QMenu(&menuBar); + QVERIFY(!menu->platformMenu()); + + menuBar.addMenu(menu); + QVERIFY(menu->platformMenu()); +} + void tst_QMenuBar::slotForTaskQTBUG53205() { QWidget *parent = taskQTBUG53205MenuBar->parentWidget(); -- cgit v1.2.3