diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index a92a4ed89dcab8bd078683bb86cfd4dc61b503c9..2e351302f5f4684f52d3c7b6bc6a3dfa19776a34 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -334,8 +334,12 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting) _toolbox->setChildToolboxes(); } -QGCApplication::~QGCApplication() +void QGCApplication::_shutdown(void) { + // This code is specifically not in the destructor since the application object may not be available in the destructor. + // This cause problems for deleting object like settings which are in the toolbox which may have qml references. By + // moving them here and having main.cc call this prior to deleting the app object we make sure app object is still + // around while these things are shutting down. #ifndef __mobile__ MainWindow* mainWindow = MainWindow::instance(); if (mainWindow) { @@ -346,6 +350,11 @@ QGCApplication::~QGCApplication() delete _toolbox; } +QGCApplication::~QGCApplication() +{ + // Place shutdown code in _shutdown +} + void QGCApplication::_initCommon(void) { QSettings settings; diff --git a/src/QGCApplication.h b/src/QGCApplication.h index c080b249011e734cf8eb3ec6bb8aacb66c1a3dce..f5234c533ddb077e4659c3d62b71e3fc4a7478df 100644 --- a/src/QGCApplication.h +++ b/src/QGCApplication.h @@ -152,6 +152,12 @@ public: static QGCApplication* _app; ///< Our own singleton. Should be reference directly by qgcApp +public: + // Although public, these methods are internal and should only be called by UnitTest code + + /// Shutdown the application object + void _shutdown(void); + private slots: void _missingParamsDisplay(void); diff --git a/src/main.cc b/src/main.cc index 4dec260fa0bc31e3c518ee9d8851624672144c67..8c2ff2ddc39e6e92d4ab06a6bdae70a87096af9d 100644 --- a/src/main.cc +++ b/src/main.cc @@ -253,6 +253,7 @@ int main(int argc, char *argv[]) exitCode = app->exec(); } + app->_shutdown(); delete app; //-- Shutdown Cache System destroyMapEngine();