-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
79 lines (71 loc) · 2.33 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
/***************************************************/
/* MagicLitePlanet */
/* Copyright (c) 2017-2022 by bytecho.net */
/* Written by Henry */
/* Function: */
/* Communication, activity, management and approval*/
/***************************************************/
#include "mainwindow.h"
#include "formlogin.h"
#include <QApplication>
//日志文件
void customMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg)
{
Q_UNUSED(context);
QMutex m_LogMutex;
QString txt;
switch (type)
{
case QtDebugMsg:
txt = QString("[%2][Info] %1").arg(msg, QDateTime::currentDateTime().toString("HH:mm:ss"));
break;
case QtWarningMsg:
txt = QString("[%2][Warning] %1").arg(msg, QDateTime::currentDateTime().toString("HH:mm:ss"));
break;
case QtCriticalMsg:
txt = QString("[%2][Critical] %1").arg(msg, QDateTime::currentDateTime().toString("HH:mm:ss"));
break;
case QtFatalMsg:
txt = QString("[%2][Fatal] %1").arg(msg, QDateTime::currentDateTime().toString("HH:mm:ss"));
abort();
}
m_LogMutex.lock();
QFile outFile(QString("%1/log/%2.log").arg(QDir::currentPath(), QDateTime::currentDateTime().toString("yyyy-MM-dd")));
outFile.open(QIODevice::WriteOnly | QIODevice::Append);
QTextStream ts(&outFile);
ts << txt << endl;
outFile.close();
m_LogMutex.unlock();
}
//初始化必要目录
void initNecessaryDir()
{
QDir dir = QDir::currentPath();
if (!dir.exists("cache"))
dir.mkdir("cache");
if (!dir.exists("log"))
dir.mkdir("log");
if (!dir.exists("update"))
dir.mkdir("update");
}
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); //开启高缩放支持图片
QApplication a(argc, argv);
#ifdef QT_NO_DEBUG
qInstallMessageHandler(customMessageHandler); //release模式下注册日志处理函数
#endif
initNecessaryDir();
formLogin *formLoginWindow = new formLogin();
if(formLoginWindow->exec() == QDialog::Accepted)
{
MainWindow w(nullptr, formLoginWindow);
formLoginWindow->send(); //发送登录信息信号
delete formLoginWindow;
w.show();
return a.exec();
}
delete formLoginWindow;
return 0;
}