-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
125 lines (103 loc) · 3.2 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QtQml>
#include <QDateTime>
#include <iostream>
#include "filterpropertymodel.h"
void registrationTypes()
{
qmlRegisterType<FilterPropertyModel>("com.monkey.models", 1, 0, "FilterPropertyModel");
}
void customMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
Q_UNUSED(context);
if (type == QtWarningMsg)
return;
QString dt = QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss");
QString date = QDateTime::currentDateTime().toString("dd.MM.yyyy");
QString txt = QString("[%1] ").arg(dt);
//ConfigureInner &con = ConfigureInner::Instance();
switch (type)
{
case QtDebugMsg: {
//if (con.log()){
//ConsoleTextColor color(ConsoleTextColor::ForeGroundWhite);
txt += QString("[Debug]: %1").arg(msg);
std::cout << txt.toStdString() << std::endl;
break;
//}
}
#ifndef QT_NO_DEBUG
txt += QString("[Debug]: %1").arg(msg);
std::cout << txt.toStdString() << std::endl;
break;
#else
return;
#endif
case QtWarningMsg: {
//ConsoleTextColor color(ConsoleTextColor::ForeGroundYellow);
#ifndef QT_NO_DEBUG
txt += QString("[Warning]: %1").arg(msg);
std::cout << txt.toStdString() << std::endl;
break;
#else
return;
#endif
}
case QtCriticalMsg: {
//ConsoleTextColor color(ConsoleTextColor::ForeGroundRed);
txt += QString("[Critical]: %1").arg(msg);
std::cout << txt.toStdString() << std::endl;
break;
}
case QtFatalMsg: {
//ConsoleTextColor color(ConsoleTextColor::ForeGroundRed);
txt += QString("[Fatal]: %1").arg(msg);
std::cout << txt.toStdString() << std::endl;
abort();
break;
}
case QtInfoMsg: {
//ConsoleTextColor color(ConsoleTextColor::ForeGroundWhite);
txt += QString("[Info]: %1").arg(msg);
std::cout << txt.toStdString() << std::endl;
break;
}
default:{
//ConsoleTextColor color(ConsoleTextColor::ForeGroundWhite);
txt += QString("[Info]: %1").arg(msg);
std::cout << txt.toStdString() << std::endl;
break;
}
}
#ifdef QT_NO_DEBUG
QDir logsDir("logs");
if (!logsDir.exists()) {
if (!QDir("./").mkpath("logs")) {
std::cout << "don't created logs directory." << std::endl;
}
}
QString outPath = "logs/" + date + ".log";
QFile outFile(outPath);
if (!outFile.open(QIODevice::WriteOnly | QIODevice::Append)) {
std::cout << "don't logs file." << std::endl;
}
QTextStream textStream(&outFile);
textStream << txt << "\r\n";
#endif
}
int main(int argc, char *argv[])
{
#ifdef QT_NO_DEBUG
qInstallMessageHandler(customMessageHandler);
#endif
QApplication app(argc, argv);
QApplication::setOrganizationName("MonkeySoft");
QApplication::setOrganizationDomain("MonkeySoft.com");
QApplication::setApplicationName("MonkeySoft");
QQmlApplicationEngine engine;
registrationTypes();
QSettings userSettings("MonkeySoft", "User");
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}