Details
-
Bug
-
Resolution: Won't Do
-
P4: Low
-
None
-
5.11.1
-
None
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