diff --git a/src/core/qgsapplication.cpp b/src/core/qgsapplication.cpp index 7ae4e9736e1..dbb0fae7d13 100644 --- a/src/core/qgsapplication.cpp +++ b/src/core/qgsapplication.cpp @@ -19,11 +19,10 @@ #include "qgsproviderregistry.h" #include +#include #include -#include - -#include +#include "qgsconfig.h" // for htonl #ifdef WIN32 @@ -68,6 +67,21 @@ QgsApplication::QgsApplication( int & argc, char ** argv, bool GUIenabled ) QgsApplication::~QgsApplication() {} +bool QgsApplication::notify( QObject * receiver, QEvent * event ) +{ + // Send event to receiver and catch unhandled exceptions + bool done = true; + try + { + done = QApplication::notify( receiver, event ); + } + catch ( std::exception & e ) + { + QMessageBox::critical( activeWindow(), tr( "Exception" ), e.what() ); + } + return done; +} + void QgsApplication::setPrefixPath( const QString thePrefixPath, bool useDefaultPaths ) { mPrefixPath = thePrefixPath; diff --git a/src/core/qgsapplication.h b/src/core/qgsapplication.h index 64fea75959f..59a1fb46ccf 100644 --- a/src/core/qgsapplication.h +++ b/src/core/qgsapplication.h @@ -28,6 +28,9 @@ class CORE_EXPORT QgsApplication: public QApplication QgsApplication( int & argc, char ** argv, bool GUIenabled ); virtual ~QgsApplication(); + //! Catch exceptions when sending event to receiver. + virtual bool notify( QObject * receiver, QEvent * event ); + /** Set the active theme to the specified theme. * The theme name should be a single word e.g. 'default','classic'. * The theme search path usually will be pkgDataPath + "/themes/" + themName + "/"