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

[Reg 5.15 -> 6.x] Crash if QMenu::deleteLater() is processed by a nested event loop

XMLWordPrintable

    • Linux/X11, macOS, Windows

      Steps to reproduce

      #include <QtWidgets>
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
      
          QMenu *menu = new QMenu;
          QObject::connect(menu, &QMenu::aboutToHide, menu, &QObject::deleteLater);
          QObject::connect(menu, &QMenu::destroyed, []{ qDebug("Menu is destroyed"); });
      
          menu->addAction("Click me", qApp, []
          {
              QMessageBox::warning(nullptr, "Warning", "It's gonna blow!");
          });
          menu->popup(QApplication::primaryScreen()->availableGeometry().center());
      
          return app.exec();
      }
      
      1. Build and run the above code.
      2. When you click the menu, you will see the QMessageBox appear and you will see the "Menu is destroyed" in the debug output.
      3. When you dismiss the QMessageBox, the app will crash.

      Tested platforms

      Customer reported this on an M1 macOS; I reproduced this on my Windows 10 machine.

       

      Workaround

      Don't delete the menu (at least not while the QMessageBox is executing)

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

            tvete Paul Olav Tvete
            skoh-qt Sze Howe Koh
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes