Unsolved Strange crash with QObject hierarchy deletion
-
Q(Core|Gui)Application is a special object and I would pass it as parent to an object for automatic destruction. The QApplication dtor is cleaning up a lot of stuff internally and then wants to delete it's children. This may work but since all is cleaned up already it may crash as you've noticed. The problem here is that the global 'qApp' instance is already set to nullptr when your widget finally gets destroyed which results in a nullptr access.
-
I'm not convinced, it should be working in my opinion.
-
qApp is set to nullptr in the second line of QCoreApplication dtor. Here's the backtrace
1652 qApp->d_func()->sendSyntheticEnterLeave(this); (gdb) bt #0 QWidget::~QWidget (this=0x6abef0, __in_chrg=<optimized out>) at /home/chehrlic/kde/qt5/qtbase/src/widgets/kernel/qwidget.cpp:1652 #1 0x000000000040352d in NotificationManager::~NotificationManager() () #2 0x0000000000403599 in NotificationManager::~NotificationManager() () #3 0x00007ffff6e07eda in QObjectPrivate::deleteChildren (this=this@entry=0x61f1d0) at /home/chehrlic/kde/qt5/qtbase/src/corelib/kernel/qobject.cpp:2004 #4 0x00007ffff6e09362 in QObject::~QObject (this=<optimized out>, __in_chrg=<optimized out>) at /home/chehrlic/kde/qt5/qtbase/src/corelib/kernel/qobject.cpp:1030 #5 0x00007ffff6dd29e3 in QCoreApplication::~QCoreApplication (this=0x7fffffffd960, __in_chrg=<optimized out>) at /home/chehrlic/kde/qt5/qtbase/src/corelib/kernel/qcoreapplication.cpp:894 #6 0x00007ffff7237790 in QGuiApplication::~QGuiApplication (this=0x7fffffffd960, __in_chrg=<optimized out>) at /home/chehrlic/kde/qt5/qtbase/src/gui/kernel/qguiapplication.cpp:641
feel free to create a bug report and ask thiago :)
-
@Christian-Ehrlicher said in Strange crash with QObject hierarchy deletion:
feel free to create a bug report and ask thiago
I just may.
-
Workarounds:
- Move the object to the stack:
class Application : public QApplication { Q_OBJECT public: Application(int& argc, char** argv); virtual ~Application(); private: NotificationManager m_notificationManager; }; Application::Application(int& argc, char** argv) : QApplication(argc, argv), m_notificationManager(this) { }
- Delete manually in
Application::~Application
.
-
Reported as QTBUG-71545.
-
Hi,
QScopedPointer might also be of interest.
-
@kshegunov said in Strange crash with QObject hierarchy deletion:
Workarounds:
- Move the object to the stack:
...
- Delete manually in
Application::~Application
.
- (For programs that don't subclass QApplication) Delete manually in a lambda connected to
QCoreApplication::aboutToQuit()
-
@kshegunov Thank you for taking your time to investigate this. I've already tried these workarounds, as stated in the original post. But it's nice to know that I've found a bug and it's not just some misunderstanding on my side. It's been making me crazy for the last day or so :)
-
@pozdnyakov said in Strange crash with QObject hierarchy deletion:
But it's nice to know that I've found a bug and it's not just some misunderstanding on my side. It's been making me crazy for the last day or so :)
Thiago says it won't be fixed. So act accordingly.