-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.cpp
72 lines (59 loc) · 1.64 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
#include "ventoy2disk.h"
#include "getroot.h"
#include <QApplication>
#include<QTranslator>
#include<QDateTime>
#include<QMutex>
#include<QFile>
#include<QTextStream>
void MessageOutPut(QtMsgType type, const QMessageLogContext &context, const QString &msg);
int main(int argc, char *argv[])
{
qInstallMessageHandler(MessageOutPut);
QApplication a(argc, argv);
Ventoy2Disk w;
getroot dlg;
//关联子窗口的show信号
QObject::connect(&dlg,SIGNAL(showmainwindow(QString)),&w,SLOT(init(QString)));
//关联子窗口的close信号
QObject::connect(&dlg,SIGNAL(quit()),&a,SLOT(quit()));
//显示验证窗口
dlg.show();
//w.show();
return a.exec();
}
void MessageOutPut(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
Q_UNUSED(context);
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;
default:
break;
}
//日志写到文件
QString current_date_time = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
QString message = QString("%1 %2%3").arg(current_date_time).arg(text).arg(msg);
QFile file(LOG_FILE);
//方式:Append为追加,WriteOnly,ReadOnly
file.open(QIODevice::WriteOnly | QIODevice::Append);
QTextStream text_stream(&file);
text_stream << message << "\r\n";
file.flush();
file.close();
mutex.unlock();
}