itom
Loading...
Searching...
No Matches
main.h
1/* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2020, Institut für Technische Optik (ITO),
5 Universität Stuttgart, Germany
6
7 This file is part of itom.
8
9 itom is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Library General Public Licence as published by
11 the Free Software Foundation; either version 2 of the Licence, or (at
12 your option) any later version.
13
14 itom is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17 General Public Licence for more details.
18
19 You should have received a copy of the GNU Library General Public License
20 along with itom. If not, see <http://www.gnu.org/licenses/>.
21*********************************************************************** */
22
23#ifndef MAIN_H
24#define MAIN_H
25
26#include <qapplication.h>
27#include <qdebug.h>
28#include <QMetaEnum>
29#include <iostream>
30#include "opencv2/opencv.hpp"
31
32class QItomApplication : public QApplication
33{
34 Q_OBJECT
35public:
36
37 QItomApplication ( int & argc, char ** argv ) : QApplication(argc,argv) {}
38
39 bool notify ( QObject * receiver, QEvent * event )
40 {
41 try
42 {
43 /*int type = event ? event->type() : -1;
44
45 if (type == 68 || type == 74 || type == 69)
46 {
47 QString className = receiver->metaObject()->className();
48 if (className == "ito::ScriptDockWidget")
49 {
50 int j = 1;
51 }
52 }*/
53 return QApplication::notify(receiver,event);
54 }
55 catch (cv::Exception &exc)
56 {
57 QString name = QString("%1 (%2)").arg(receiver->objectName()).arg(receiver->metaObject()->className());
58 qWarning("Itom-Application has caught a cv::exception");
59 qWarning() << (exc.err).c_str() << " from" << name;
60 //qDebug() << "Itom-Application caught an exception from" << receiver->objectName() << "from event type" << event->type();
61#ifdef _DEBUG
62 qFatal("Exiting due to exception caught. OpenCV-Exception: %s", (exc.err).c_str());
63#endif
64 std::cerr << "Itom-Application has caught a cv::exception: " << (exc.err).c_str() << " from: " << name.toLatin1().constData() << "\n" << std::endl;
65 }
66 catch(std::exception &exc)
67 {
68 QString name = QString("%1 (%2)").arg(receiver->objectName()).arg(receiver->metaObject()->className());
69 qWarning("Itom-Application has caught a std::exception");
70 qWarning() << "Message:" << exc.what() << " from" << name;
71#ifdef _DEBUG
72 qFatal("Exiting due to std::exception caught. Exception: %s", exc.what());
73#endif
74 std::cerr << "Itom-Application has caught a std::exception: " << exc.what() << " from: " << name.toLatin1().constData() << "\n" << std::endl;
75 }
76 catch (...)
77 {
78 int enumIdx = QEvent::staticMetaObject.indexOfEnumerator("Type");
79 QMetaEnum me = QEvent::staticMetaObject.enumerator(enumIdx);
80 QByteArray key = event ? me.valueToKeys(event->type()) : QByteArray("");
81 int type = event ? event->type() : -1;
82 QString name = QString("%1 (%2)").arg(receiver->objectName()).arg(receiver->metaObject()->className());
83 qWarning("Itom-Application has caught an unknown exception");
84 qWarning() << "Itom-Application caught an unknown exception from" << name << "from event type" << type << " (" << key.constData() << ")";
85#ifdef _DEBUG
86 qFatal("Exiting due to exception caught");
87#endif
88 std::cerr << "Itom-Application caught an unknown exception from: " << name.toLatin1().constData() << " from event type " << type << " (" << key.constData() << ")" << "\n" << std::endl;
89 }
90 return false;
91 }
92};
93
94#endif
Definition main.h:33