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

Crash in ~QApplication: garbage collector of the QWidgets

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • Icon: P2: Important P2: Important
    • None
    • 6.2.4
    • None
    • Windows 11
    • Windows

      I have written a code with a QApplication creating the QMainWindow. In this scheme, the QMainWindow is, by default, not on mode DeleteOnClose.

       

      In the destructor of QApplication, there is the following loop:

              for (QWidgetSet::ConstIterator it = mySet->constBegin(), cend = mySet->constEnd(); it != cend; ++it) {
                  QWidget *w = *it;
                  if (!w->parent())                        // window
                      w->destroy(true, true);
              }
       

      So, when w is the QMainWindow, destroy() is called. And all the children of QMainWindow are deleted. Then, the list mySet contains inconsistencies. Because all widgets of the MainWindow are still present, but deleted. So, when the test (!w->parent()) occurs on a deleted QWidget, a crash occurs (in debug mode). 

       

      For the MainWindow, the option is to add WA_DeleteOnClose to avoid this problem. But it is possible for other QWidget not having parent, and having children.

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

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            alakauf Alain Kaufmann
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes