ATLAS Offline Software
Loading...
Searching...
No Matches
VP1QtApplication.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
6// //
7// Implementation file for class VP1QtApplication //
8// //
9// Author: Riccardo Maria BIANCHI <rbianchi@cern.ch> //
10// //
11// This class reimplements the basic notify() method //
12// of the QApplication class, in order to catch //
13// exceptions from C++, and to avoid fatal errors //
14// like: //
15// "Qt has caught an exception thrown from an event //
16// handler. Throwing exceptions from an event handler //
17// is not supported in Qt. You must reimplement //
18// QApplication::notify() and catch all exceptions //
19// there. //
20// //
21// //
22// Initial version: 19 November 2012 //
23// //
25
26
27// include VP1
29#include "VP1Base/VP1Msg.h"
30
31// include Qt
32#include <QEvent>
33
34// include C++
35#include <typeinfo>
36//#include <stddef.h> // this to fix the 'ptrdiff_t' does not name a type error with Qt (http://qt-project.org/forums/viewthread/16992)
37
38
39bool VP1QtApplication::notify(QObject *rec, QEvent *ev)
40{
41 //std::cout << (3, "Called VP1QtApplication::notify()") << std::endl;
42
43 // only for debug
44 //VP1Msg::message("VP1QtApplication:notify()");
45
46 // for normal events we pass to QApplication:notify()...
47 try {
48 return QApplication::notify(rec, ev);
49 }
50 catch (std::exception &e) {
51 VP1Msg::message("VP1QtApplication: std::exception: ");
52 qWarning("VP1QtApplication: Error '%s' sending event '%s' to object '%s' ('%s')",
53 e.what(), typeid(*ev).name(), qPrintable(rec->objectName()),
54 typeid(*rec).name());
55 qWarning("throwing the exception again...");
56 throw e;
57 return false;
58 }
59 catch (char const *str) {
60 VP1Msg::message("VP1QtApplication: EXCEPTION: " + QString(str) );
61 return false;
62 }
63 catch (...) {
64 VP1Msg::message("VP1QtApplication: Unknown exception!");
65 return false;
66 }
67 //VP1Msg::message("VP1QtApplication: outside catch..."); // only for DEBUG
68 return false;
69}
static void message(const QString &, IVP1System *sys=0)
Definition VP1Msg.cxx:30
virtual bool notify(QObject *rec, QEvent *ev)
int ev
Definition globals.cxx:25