Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-13749

On Mac, menu actions no longer trigger after calling menu.clear() and repopulating inside of a slot triggered by the menu aboutToShow() signal

    XMLWordPrintable

Details

    • macOS

    Description

      This test case fails:

      void TestQtAPI::slotAboutToShowMenu() {
      	if (menu != NULL) {
      		menu->clear();
      		menu->addAction("Dummy", &loop, SLOT(quit()));
      	}
      }
      
      void TestQtAPI::testSubmenuWorksWithoutWindows() {
      	QMenuBar mb;
      	menu = mb.addMenu("Dummy");
      	menu->addAction("Dummy", &loop, SLOT(quit()));
      	connect(menu, SIGNAL(aboutToShow()), this, SLOT(slotAboutToShowMenu()));
      	
      	QPoint inside1(150, 10);
          QPoint inside2 = inside1 + QPoint(0, 30);
      	
      	// Post a click to press the menu item:
      	NativeEventList native;
          native.append(new QNativeMouseButtonEvent(inside1, Qt::LeftButton, 1, Qt::NoModifier));
          native.append(new QNativeMouseButtonEvent(inside1, Qt::LeftButton, 0, Qt::NoModifier));
          native.append(new QNativeMouseButtonEvent(inside2, Qt::LeftButton, 1, Qt::NoModifier));
      	native.append(new QNativeMouseButtonEvent(inside2, Qt::LeftButton, 0, Qt::NoModifier));
      
          // Add a backup timer to end the test if we fail:
          QTimer dontHang;
          dontHang.setSingleShot(true);
          connect(&dontHang, SIGNAL(timeout()), &loop, SLOT(quit()));
          dontHang.start(3000);
      
          native.play(NativeEventList::ReturnImmediately);
          loop.exec();
          QVERIFY2(dontHang.isActive(), "The item was not triggered!");
      }
      

      Replacing the call to connect() with slotAboutToShowMenu() results in the test passing.

      Being able to clear and repopulate a menu is useful when implementing a Recent Items list for an application.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            richard Richard Moe Gustavsen
            jmckisson John McKisson
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes