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

QCoreApplication doesn't delete its children before setting itself to null

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Do
    • P4: Low
    • None
    • 5.11.1
    • Core: Object Model
    • None
    • All

    Description

      QCoreApplication relies on the QObject destructor to free its children objects. However this means that when one of the child objects holds a visible widget the program will segfault.

      Here the application invalidates the static pointer, but it does not delete its children beforehand.

      Code to reproduce:

      class NotificationManager : public QObject
      {
          Q_OBJECT
      
      public:
          NotificationManager(QObject * = nullptr);
      
      private:
          QWidget widget;
      };
      
      inline NotificationManager::NotificationManager(QObject * parent)
          : QObject(parent)
      {
          widget.show();
      //    QMetaObject::invokeMethod(&widget, &QWidget::close, Qt::QueuedConnection);
      }
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
      
          new NotificationManager(&app);
          QMetaObject::invokeMethod(&app, &QApplication::quit, Qt::QueuedConnection);
      
          return app.exec();
      }
      

      Adding:

      if (!d->children.isEmpty())
              d->deleteChildren();
      

      before the global cleanup handlers in the QCoreApplication destructor should be enough fix it.

      Problem reported in the forum:
      https://forum.qt.io/topic/96197/strange-crash-with-qobject-hierarchy-deletion

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            kshegunov Konstantin Shegunov
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes