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

Crash in ~QApplication: garbage collector of the QWidgets

    XMLWordPrintable

Details

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

    Description

      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.

      Attachments

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

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes