-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
67 lines (55 loc) · 1.61 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
#include "mainwindow.h"
#include <iostream>
#include <QFile>
#include <QDir>
#include <QScopedPointer>
#include <QApplication>
#include <QStyleFactory>
static QScopedPointer<QFile> m_log;
void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg) {
Q_UNUSED(context)
QTextStream outFile(m_log.data());
QString datetime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz ");
outFile << datetime;
std::cout << datetime.toLocal8Bit().toStdString();
switch (type) {
case QtDebugMsg:
std::cout << "[DEBUG] ";
outFile << "[DEBUG] ";
break;
case QtInfoMsg:
std::cout << "[INFO] ";
outFile << "[INFO] ";
break;
case QtWarningMsg:
std::cout << "[WARNING] ";
outFile << "[WARNING] ";
break;
case QtCriticalMsg:
std::cout << "[CRITICAL] ";
outFile << "[CRITICAL] ";
break;
case QtFatalMsg:
std::cout << "[FATAL] ";
outFile << "[FATAL] ";
break;
}
outFile << msg << Qt::endl;
std::cout << msg.toLocal8Bit().toStdString() << std::endl;
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
m_log.reset(new QFile(QCoreApplication::applicationDirPath() + "/log.txt"));
m_log.data()->open(QFile::Append | QFile::Text);
#ifdef Q_OS_WIN32
QApplication::setStyle(QStyleFactory::create("Fusion"));
#endif
#ifdef Q_OS_LINUX
a.setWindowIcon(QIcon(":resources/images/logo_mini.svg"));
#endif
qInstallMessageHandler(messageHandler);
MainWindow w;
w.show();
return a.exec();
}