-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.cpp
96 lines (85 loc) · 3.19 KB
/
main.cpp
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
#include "mainwindow.h"
#include <QApplication>
#include <QSslSocket>
#include <QtCore>
// turns on logging of context (file+line number) in c++
#define QT_MESSAGELOGCONTEXT
void myMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg)
{
QString txt;
QDateTime now = QDateTime::currentDateTime();
int offset = now.offsetFromUtc();
now.setOffsetFromUtc(offset);
#if defined(Q_OS_LINUX)
if (!QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)).exists()) {
QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
}
QFile outFile(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QDir::separator() + "geotagging.log");
#elif (defined(Q_OS_WIN) || defined(Q_OS_WIN32) || defined(Q_OS_WIN64))
QFile outFile("geotagging.log");
#else
QFile outfile("geotagging.log");
#endif
outFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text);
QTextStream ts(&outFile);
QTextStream std_out(stdout, QIODevice::WriteOnly);
QTextStream std_err(stderr, QIODevice::WriteOnly);
switch (type) {
case QtDebugMsg:
txt = QString("%1 [D] %2:%3 @ %4(): %5").arg(now.toString(Qt::ISODate)).arg(context.file).arg(context.line).arg(context.function).arg(msg);
#if QT_VERSION < 0x051400
std_out << txt << endl;
#else
std_out << txt << Qt::endl;
#endif
break;
case QtWarningMsg:
txt = QString("%1 [W]: %2:%3 @ %4(): %5").arg(now.toString(Qt::ISODate)).arg(context.file).arg(context.line).arg(context.function).arg(msg);
#if QT_VERSION < 0x051400
std_out << txt << endl;
#else
std_out << txt << Qt::endl;
#endif
break;
case QtCriticalMsg:
txt = QString("%1 [C]: %2:%3 @ %4(): %5").arg(now.toString(Qt::ISODate)).arg(context.file).arg(context.line).arg(context.function).arg(msg);
#if QT_VERSION < 0x051400
std_out << txt << endl;
#else
std_out << txt << Qt::endl;
#endif
break;
case QtFatalMsg:
txt = QString("%1 [F]: %2:%3 @ %4(): %5").arg(now.toString(Qt::ISODate)).arg(context.file).arg(context.line).arg(context.function).arg(msg);
#if QT_VERSION < 0x051400
std_out << txt << endl;
#else
std_out << txt << Qt::endl;
#endif
abort();
default:
txt = QString("%1 [O]: %2:%3 @ %4(): %5").arg(now.toString(Qt::ISODate)).arg(context.file).arg(context.line).arg(context.function).arg(msg);
#if QT_VERSION < 0x051400
std_out << txt << endl;
#else
std_out << txt << Qt::endl;
#endif
break;
}
#if QT_VERSION < 0x051400
ts << txt << endl;
#else
ts << txt << Qt::endl;
#endif
outFile.close();
}
int main(int argc, char* argv[])
{
QApplication a(argc, argv);
qInstallMessageHandler(myMessageHandler);
qDebug() << "Starting build " << QString::fromLocal8Bit(GIT_VERSION) << " " << QString::fromLocal8Bit(__DATE__) << " " << QString::fromLocal8Bit(__TIME__) << "Qt:" << qVersion();
qDebug() << "supportsSsl" << QSslSocket::supportsSsl() << "build version:" << QSslSocket::sslLibraryBuildVersionString() << "library version:" << QSslSocket::sslLibraryVersionString();
MainWindow w;
w.show();
return a.exec();
}