-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
56 lines (47 loc) · 1.35 KB
/
main.cpp
File metadata and controls
56 lines (47 loc) · 1.35 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
#include <QApplication>
#include <windows.h>
#include <winuser.h>
#include "StickyNote/StickyNote.h"
#include <QMessageLogContext>
#include <QDateTime>
#include <QFile>
void writeToLog(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
QString prefix;
switch (type) {
case QtDebugMsg:
prefix = "Debug";
break;
case QtInfoMsg:
prefix = "Info";
break;
case QtWarningMsg:
prefix = "Warning";
break;
case QtCriticalMsg:
prefix = "Critical";
break;
case QtFatalMsg:
prefix = "Fatal";
break;
}
QString fileName = "run_" + QDateTime::currentDateTime().toString("yyyyMMdd") + ".log";
// QFile logFile(QApplication::applicationDirPath() + "log/" + fileName);
QFile logFile("./my_log.txt");
if (logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text))
{
QTextStream out(&logFile);
out << msg <<"\n";
logFile.close();
}
// 对于QtFatalMsg,确保标准处理被执行(默认是终止程序)
if (type == QtFatalMsg)
abort();
}
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
// qInstallMessageHandler(writeToLog);
qDebug()<<"init";
StickyNote::StickyNote s;
s.show();
return a.exec();
}