diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index c47f5ca..2a6dc2d 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -553,7 +553,7 @@ bool QGCApplication::_initForNormalAppBoot() QQuickImageProvider* pImgProvider = dynamic_cast(qgcApp()->toolbox()->imageProvider()); _qmlAppEngine->addImageProvider(QStringLiteral("QGCImages"), pImgProvider); - QQuickWindow* rootWindow = (QQuickWindow*)qgcApp()->mainRootWindow(); + QQuickWindow* rootWindow = qgcApp()->mainRootWindow(); if (rootWindow) { rootWindow->scheduleRenderJob (new FinishVideoInitialization (toolbox()->videoManager()), @@ -788,10 +788,10 @@ void QGCApplication::_showDelayedAppMessages(void) } } -QQuickItem* QGCApplication::mainRootWindow() +QQuickWindow* QGCApplication::mainRootWindow() { if(!_mainRootWindow) { - _mainRootWindow = reinterpret_cast(_rootQmlObject()); + _mainRootWindow = qobject_cast(_rootQmlObject()); } return _mainRootWindow; } @@ -1014,3 +1014,24 @@ bool QGCApplication::compressEvent(QEvent*event, QObject* receiver, QPostEventLi return false; } + +bool QGCApplication::event(QEvent *e) +{ + if (e->type() == QEvent::Quit) { + // On OSX if the user selects Quit from the menu (or Command-Q) the ApplicationWindow does not signal closing. Instead you get a Quit even here only. + // This in turn causes the standard QGC shutdown sequence to not run. So in this case we close the window ourselves such that the + // signal is sent and the normal shutdown sequence runs. + bool forceClose = _mainRootWindow->property("_forceClose").toBool(); + qDebug() << "Quit event" << forceClose; + // forceClose + // true: Standard QGC shutdown sequence is complete. Let the app quit normally by falling through to the base class processing. + // false: QGC shutdown sequence has not been run yet. Don't let this event close the app yet. Close the main window to kick off the normal shutdown. + if (!forceClose) { + // + _mainRootWindow->close(); + e->ignore(); + return true; + } + } + return QApplication::event(e); +} diff --git a/src/QGCApplication.h b/src/QGCApplication.h index 585f18b..55db399 100644 --- a/src/QGCApplication.h +++ b/src/QGCApplication.h @@ -93,7 +93,7 @@ public: QTranslator& qgcJSONTranslator(void) { return _qgcTranslatorJSON; } void setLanguage(); - QQuickItem* mainRootWindow(); + QQuickWindow* mainRootWindow(); uint64_t msecsSinceBoot(void) { return _msecsElapsedTime.elapsed(); } /// Registers the signal such that only the last duplicate signal added is left in the queue. @@ -101,6 +101,8 @@ public: void removeCompressedSignal(const QMetaMethod & method); + bool event(QEvent *e) override; + static QString cachedParameterMetaDataFile(void); static QString cachedAirframeMetaDataFile(void); @@ -203,7 +205,7 @@ private: int _buildVersion = 0; GPSRTKFactGroup* _gpsRtkFactGroup = nullptr; QGCToolbox* _toolbox = nullptr; - QQuickItem* _mainRootWindow = nullptr; + QQuickWindow* _mainRootWindow = nullptr; bool _bluetoothAvailable = false; QTranslator _qgcTranslatorSourceCode; ///< translations for source code C++/Qml QTranslator _qgcTranslatorJSON; ///< translations for json files diff --git a/src/VideoManager/VideoManager.cc b/src/VideoManager/VideoManager.cc index c6bc7a3..2b216de 100644 --- a/src/VideoManager/VideoManager.cc +++ b/src/VideoManager/VideoManager.cc @@ -13,6 +13,7 @@ #include #include #include +#include #ifndef QGC_DISABLE_UVC #include @@ -569,7 +570,7 @@ void VideoManager::_initVideo() { #if defined(QGC_GST_STREAMING) - QQuickItem* root = qgcApp()->mainRootWindow(); + QQuickWindow* root = qgcApp()->mainRootWindow(); if (root == nullptr) { qCDebug(VideoManagerLog) << "mainRootWindow() failed. No root window";