-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmain.cpp
More file actions
99 lines (92 loc) · 3.63 KB
/
main.cpp
File metadata and controls
99 lines (92 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "homescreen.h"
#include <QApplication>
#include <QVBoxLayout>
#include <QLabel>
#include <QDebug>
#include <QFile>
#include <QDir>
#include <usoundutils.h>
#include <QDateTime>
#include <defaults.h>
#include <QSettings>
#include<settingsstore.h>
#include"defaultcameraparameternames.h"
#include<QMessageBox>
QString tempString = "";
Homescreen *homeScreenPointer = 0;
void customLoggingHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
QByteArray localMsg = msg.toLocal8Bit();
QString txt;
switch (type) {
case QtDebugMsg:
txt = QString("%1 - DEBUG - %3:%4:%5 - %2").arg(QDateTime::currentDateTime().toString()).arg(localMsg.constData()).arg(context.file).arg(context.line).arg(context.function);
fprintf(stdout, "%s\n", txt.toLatin1().data());
fflush(stdout);
break;
case QtInfoMsg:
txt = QString("%1 - INFO - %2").arg(QDateTime::currentDateTime().toString()).arg(localMsg.constData());
fprintf(stdout, "%s\n", txt.toLatin1().data());
fflush(stdout);
break;
case QtWarningMsg:
txt = QString("%1 - WARNING - %2").arg(QDateTime::currentDateTime().toString()).arg(localMsg.constData());
fprintf(stdout, "%s\n", txt.toLatin1().data());
fflush(stdout);
break;
case QtCriticalMsg:
txt = QString("%1 - CRITICAL - %3:%4:%5 - %2").arg(QDateTime::currentDateTime().toString()).arg(localMsg.constData()).arg(context.file).arg(context.line).arg(context.function);
fprintf(stderr, "%s\n", txt.toLatin1().data());
fflush(stderr);
break;
case QtFatalMsg:
txt = QString("%1 - FATAL - %3:%4:%5 - %2").arg(QDateTime::currentDateTime().toString()).arg(localMsg.constData()).arg(context.file).arg(context.line).arg(context.function);
fprintf(stderr, "%s\n", txt.toLatin1().data());
fflush(stderr);
break;
}
//todo: Prathyush SP -> Set settings for log file path
QFile outFile(LOGGING_CONFIGURATION::LOG_FILE_PATH);
outFile.open(QIODevice::WriteOnly | QIODevice::Append);
QTextStream ts(&outFile);
ts << txt << Qt::endl;
// Push to Message Box
if(homeScreenPointer!=0 && Homescreen::globalMessageBox != 0 && LOGGING_CONFIGURATION::LOG_LEVEL <= type){
emit homeScreenPointer->pushToMessageBoxSignal(tempString+txt);
tempString="";
}
else if (Homescreen::logLevel <= type){
tempString+=txt+'\n';
}
}
int main(int argc, char *argv[])
{
try {
// Load Settings
SettingsStore::loadSettings();
qRegisterMetaType<QList<QLineSeries*> >("QList<QLineSeries*>");
// Setup directories
createDirectories();
qInstallMessageHandler(customLoggingHandler); // Install the handler
qInfo() << "Logging to file:" + LOGGING_CONFIGURATION::LOG_FILE_PATH;
QApplication a(argc, argv);
// This is used as a workaround to display menubar in mac os - https://stackoverflow.com/questions/25261760/menubar-not-showing-for-simple-qmainwindow-code-qt-creator-mac-os
QCoreApplication::setAttribute(Qt::AA_DontUseNativeMenuBar);
Homescreen w;
homeScreenPointer = &w;
qDebug() << "Application initialized successfully";
w.setWindowIcon(QIcon("://icons/wpi_logo.ico"));
w.show();
return a.exec();
}
catch (HalconCpp::HOperatorException &e) {
qFatal(e.ErrorMessage().Text());
}
catch (SettingsStoreException &e) {
qFatal(e.what());
QMessageBox::critical(0, "Issue with Settings",e.what(),QMessageBox::Ok);
}
catch (std::exception &e) {
qFatal(e.what());
}
}