-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
71 lines (59 loc) · 2.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
#include <QApplication>
#include <QLibraryInfo>
#include <QTextStream>
#include <QTranslator>
#include "globals.h"
#include "mainwindow.h"
void messageToFile(QtMsgType type, const QMessageLogContext &context,
const QString &msg);
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
#ifndef STOP_LOG_TO_FILE
qInstallMessageHandler(messageToFile);
#endif
QTranslator qtTranslator;
bool translate_file_loaded = qtTranslator.load("qt_en", ":/");
qDebug() << "traslate_file_loaded" << translate_file_loaded;
bool translate_loaded = a.installTranslator(&qtTranslator);
qDebug() << "translate_loaded" << translate_loaded;
MainWindow w;
w.show();
return a.exec();
}
void messageToFile(QtMsgType type, const QMessageLogContext &context,
const QString &msg) {
QFile file(QApplication::applicationDirPath() + QDir::separator() + LOG_FILE);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append)) {
return;
}
if (file.size() > MAX_LOG_FILE_SIZE) {
file.resize(0);
}
QTextStream out(&file);
switch (type) {
case QtInfoMsg:
out << QDateTime::currentDateTime().toString("dd.MM.yy hh:mm:ss:zzz")
<< " Info: " << msg << ", " << context.file << " "
<< context.function << Qt::endl;
break;
case QtDebugMsg:
// out << QDateTime::currentDateTime().toString("dd.MM.yy
// hh:mm:ss:zzz")
// << " Debug: " << msg << ", " << context.file << " "
// << context.function << endl;
break;
case QtWarningMsg:
out << QDateTime::currentDateTime().toString("dd.MM.yy hh:mm:ss:zzz")
<< " Warning: " << msg << ", " << context.file << Qt::endl;
break;
case QtCriticalMsg:
out << QDateTime::currentDateTime().toString("dd.MM.yy hh:mm:ss:zzz")
<< " Critical: " << msg << ", " << context.file << Qt::endl;
break;
case QtFatalMsg:
out << QDateTime::currentDateTime().toString("dd.MM.yy hh:mm:ss:zzz")
<< " Fatal: " << msg << ", " << context.file << Qt::endl;
break;
}
file.close();
}