From dac1bb975265d33e7aeb0e3fc0342260613af9d1 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Sat, 6 Sep 2014 14:15:08 +0100 Subject: [PATCH] Subclass QApplication to catch exceptions in handlers. --- CMakeLists.txt | 1 + main.cpp | 9 ++------- pv/application.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ pv/application.h | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 pv/application.cpp create mode 100644 pv/application.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d85948c0..2fd35b1c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -124,6 +124,7 @@ configure_file ( set(pulseview_SOURCES main.cpp + pv/application.cpp pv/devicemanager.cpp pv/mainwindow.cpp pv/sigsession.cpp diff --git a/main.cpp b/main.cpp index 07d6dc3f..5c3e5b25 100644 --- a/main.cpp +++ b/main.cpp @@ -27,13 +27,13 @@ #include -#include #include #ifdef ENABLE_SIGNALS #include "signalhandler.h" #endif +#include "pv/application.h" #include "pv/devicemanager.h" #include "pv/mainwindow.h" #ifdef ANDROID @@ -68,12 +68,7 @@ int main(int argc, char *argv[]) struct sr_context *sr_ctx = NULL; const char *open_file = NULL; - QApplication a(argc, argv); - - // Set some application metadata - QApplication::setApplicationVersion(PV_VERSION_STRING); - QApplication::setApplicationName("PulseView"); - QApplication::setOrganizationDomain("sigrok.org"); + Application a(argc, argv); #ifdef ANDROID srau_init_environment(); diff --git a/pv/application.cpp b/pv/application.cpp new file mode 100644 index 00000000..224cc600 --- /dev/null +++ b/pv/application.cpp @@ -0,0 +1,43 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2014 Martin Ling + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "application.h" +#include "config.h" + +#include + +Application::Application(int &argc, char* argv[]) : + QApplication(argc, argv) +{ + setApplicationVersion(PV_VERSION_STRING); + setApplicationName("PulseView"); + setOrganizationDomain("sigrok.org"); +} + +bool Application::notify(QObject *receiver, QEvent *event) +{ + try { + return QApplication::notify(receiver, event); + } catch (std::exception& e) { + std::cerr << "Caught exception: " << e.what() << std::endl; + exit(1); + return false; + } +} diff --git a/pv/application.h b/pv/application.h new file mode 100644 index 00000000..5a80ec86 --- /dev/null +++ b/pv/application.h @@ -0,0 +1,34 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2014 Martin Ling + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef PULSEVIEW_PV_APPLICATION_H +#define PULSEVIEW_PV_APPLICATION_H + +#include + +class Application : public QApplication +{ +public: + Application(int &argc, char* argv[]); +private: + bool notify(QObject *receiver, QEvent *event); +}; + +#endif // PULSEVIEW_PV_APPLICATION_H -- 2.30.2