-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
75 lines (58 loc) · 2.63 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
#include "mainwindow.h"
#include <QApplication>
#include <QLocale>
#include <QTranslator>
#include <QTime>
#include <QDate>
#include <QMutex>
#include "Modules/createDatabase.cpp"
#include "Modules/settings.cpp"
void customeMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg){
static QMutex mutex;
QMutexLocker lock(&mutex);
QHash<QtMsgType, QString> msgLevelHash({{QtDebugMsg, "Debug"}, {QtInfoMsg, "Info"}, {QtWarningMsg, "Warning"}, {QtCriticalMsg, "Critical"}, {QtFatalMsg, "Fatal"}});
QByteArray localMsg = msg.toLocal8Bit();
QByteArray time = QTime::currentTime().toString("hh:mm:ss.zzz").toLocal8Bit();
QByteArray date = QDate::currentDate().toString("yyyy-MM-dd").toLocal8Bit();
QString logLevelName = msgLevelHash[type];
QByteArray logLevelMsg = logLevelName.toLocal8Bit();
#ifdef QT_DEBUG
bool logToFile = false;
#else
bool logToFile = true;
#endif
if(logToFile){
QString txt = QString("%0 %1 | %2: %3 (%4)").arg(date, time, logLevelName, msg, context.file);
QFile out(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)+"/.log");
out.open(QIODevice::WriteOnly | QIODevice::Append);
QTextStream stream(&out);
stream << txt << Qt::endl;
}else{
fprintf(stderr, "%s %s | %s: %s (%s:%u, %s)\n", date.constData(), time.constData(), logLevelMsg.constData(), localMsg.constData(), context.file, context.line, context.function);
fflush(stderr);
}
if(type == QtFatalMsg){abort();}
}
int main(int argc, char *argv[]){
qInstallMessageHandler(customeMessageOutput);
QCoreApplication::setApplicationName("SpaeneRechner");
QCoreApplication::setApplicationVersion("0.7.7");
QCoreApplication::setOrganizationDomain("https://github.com/EinRainerZufall/SpaeneRechner");
qInfo() << "Das Programm wurde mit QT Version:" << QT_VERSION_STR << "kompiliert!";
qInfo() << "Kompiliert wurde am:" << __DATE__ << "um:" << __TIME__ << "Uhr";
QApplication a(argc, argv);
MainWindow w;
w.setWindowTitle(w.windowTitle() +" "+ QCoreApplication::applicationVersion());
w.setWindowIcon(QIcon(":/img/src/endmill_altin.ico"));
QTranslator translator;
const QStringList uiLanguages = QLocale::system().uiLanguages();
for (const QString &locale : uiLanguages) {
const QString baseName = "SpaeneRechner_" + QLocale(locale).name();
if (translator.load(":/i18n/" + baseName)) {
a.installTranslator(&translator);
break;
}
}
w.show();
return a.exec();
}