-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
85 lines (79 loc) · 2.48 KB
/
main.cpp
File metadata and controls
85 lines (79 loc) · 2.48 KB
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
//
// Created by aichao on 2022/5/11.
//
#include <QMutex>
#include <QApplication>
#include <QFile>
#include <QDateTime>
#include <QtWidgets>
#include "widgets/mysplashscreen.h"
#include "widgets/mywidget.h"
#include "utils/config.h"
void outputMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
static QMutex mutex;
mutex.lock();
QString text;
switch (type) {
case QtDebugMsg:
text = QString("Debug");
break;
case QtWarningMsg:
text = QString("Warning");
break;
case QtCriticalMsg:
text = QString("Critical");
break;
case QtFatalMsg:
text = QString("Fatal");
break;
case QtInfoMsg:
text = QString("Info");
break;
}
QString current_date_time = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
#if DEBUG
QString context_info = QString("File:(%1) Line(%2)").arg(QString(context.file)).arg(context.line);
QString message = QString("[%1] |【%2】|%3|%4").arg(current_date_time, text, context_info, msg);
#else
QString message = QString("[%1]|【%2】| %3").arg(current_date_time, text, msg);
#endif
QDateTime date_time = QDateTime::currentDateTime();
QString log_dir = QApplication::applicationDirPath() + "/framLog/" + date_time.toString("yyyyMM");
QDir dir(log_dir);
if (!dir.exists()) {
dir.mkpath(log_dir);
}
QString date = QDateTime::currentDateTime().toString("dd");
QString base_log_file = Config::getInstance().get_logFile();
QString log_file = log_dir + "/" + base_log_file + "_" + date + ".txt";
QFile file(log_file);
file.open(QIODevice::WriteOnly | QIODevice::Append);
QTextStream text_stream(&file);
text_stream << message << "\r\n";
file.flush();
file.close();
mutex.unlock();
}
int main(int argc, char *argv[]) {
#ifndef __linux__
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
#else
qputenv("QT_IM_MODULE", QByteArray("Qt5Input"));
#endif
QApplication a(argc, argv);
if (Config::getInstance().get_isWriteLog()) {
qInstallMessageHandler(outputMessage);
}
MySplashScreen::getInstance().show();
MyWidget w;
MySplashScreen::getInstance().finish(&w);
#ifdef __linux__
// 隐藏鼠标,因为有触屏
QApplication::setOverrideCursor(Qt::BlankCursor);
w.setMaximumSize(1000,1000);
w.showFullScreen();
#else
w.show();
#endif
return a.exec();
}