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

[REG] QCoreApplication::processEvents() processes deferred delete

    XMLWordPrintable

Details

    • 52ce4d2d2 (dev), 2800481b0 (6.4), 927ce8c4f (6.5), 73f33e4da (tqtc/lts-6.2)

    Description

      Qt6 differently processes Qt::WA_DeleteOnClose than Qt5. With Qt6 is possible to cause a crash by calling QCoreApplication::processEvents() inside slot as described in snippet below.

      void MainWindow::showMenu()
      {
          QMenu *menu = new QMenu(this);
          menu->setAttribute(Qt::WA_DeleteOnClose);
          menu->addAction(ui->actionStart);
          menu->popup(QCursor::pos());
      }
      
      void MainWindow::startTriggered()
      {
          for (int i = 0; i <= 100; i += 1)
          {
              ui->progressBar->setValue(i);
              /* First call to processEvents() triggers QMenu destructor on Qt 6
               * QMenu is deleted but the object is still needed by code on stack!
               * When this function finishes and the code on stack uses now-deleted
               * QMenu object and memory corruption occurs.
               *
               * On Release builds the crash usually happens the second time the
               * action is triggered. When debugging Debug builds in Visual Studio
               * the exception is seen after first trigger.
               * 
               * This code works perfectly fine with Qt 5.
               */
              QCoreApplication::processEvents();
          }
      }
      

      Attached is minimal reproducible example that triggers a crash on Qt 6 but works perfectly fine with Qt 5.

      Attachments

        Issue Links

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

          Activity

            People

              vhilshei Volker Hilsheimer
              desowin Tomasz Moń
              Votes:
              1 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes