OpenLexocad  28.0
LxApplication.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <QApplication>
4 #include <QMessageBox>
5 #include <QDebug>
6 
7 
8 
9 class LxApplication : public QApplication
10 {
11 public:
12  LxApplication(int& argc, char** argv) : QApplication(argc, argv)
13  {}
14 
15  virtual bool winEventFilter(MSG* /*msg*/, long* /*result*/)
16  {
17  return false;
18  }
19 
20  virtual bool notify( QObject * receiver, QEvent * event ) override
21  {
22 
23  if( catchExceptions )
24  {
25  try
26  {
27  return QApplication::notify(receiver, event);
28  }
29  catch( std::runtime_error& er )
30  {
31  QString msg = QString("Uncaught Exception! ") + QString(er.what());
32  QMessageBox::critical(0, "Exception", msg );
33  }
34  catch(const std::exception& ex)
35  {
36  QString msg = QString("Uncaught Exception! ") + QString(ex.what());
37  QMessageBox::critical(0, "Exception", msg );
38  }
39  catch(...)
40  {
41  // may be handle exception here ...
42  // TODO Dietmar
43  qDebug() << "Attention. Uncaught Exception! Forgot to catch exception?";
44 
45  // HPK 2021-09-23: Deactivated critical message. It drives Andreas crazy.
46  // TODO -> Dietmar
47  // QMessageBox::critical(0, "Attention", QString("<b>Uncaught Exception! Forgot to catch exception?</b>"));
48  }
49  }
50  else
51  return QApplication::notify(receiver, event);
52 
53 
54  return false;
55 
56  }
57 
58 
59 
60 
61  bool catchExceptions = true;
62 
63 
64 
65 };
66 
67 #define lxApp (static_cast<LxApplication *>(QCoreApplication::instance()))
LxApplication::winEventFilter
virtual bool winEventFilter(MSG *, long *)
Definition: LxApplication.h:15
LxApplication::LxApplication
LxApplication(int &argc, char **argv)
Definition: LxApplication.h:12
LxApplication::catchExceptions
bool catchExceptions
Definition: LxApplication.h:61
LxApplication
Definition: LxApplication.h:10
LxApplication::notify
virtual bool notify(QObject *receiver, QEvent *event) override
Definition: LxApplication.h:20