-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
56 lines (45 loc) · 1.67 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
#include "memoryapplication.h"
#ifdef Q_OS_WIN
#include "app_dump.h"
#endif
void logmessagehander(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
static QMutex logmessagelock;
QMutexLocker locker(&logmessagelock);
const char *function = context.function ? context.function : "";
QString time = QDateTime::currentDateTime().toString("yyyy-MM-dd hh-mm-ss");
QString OutMsg = time + QString(" %1 :").arg(function) + msg + "\n";
static QFile *logfile = nullptr;
if (!logfile)
{
QDir logdir(runtimedir + "/logs");
if (!logdir.exists())
logdir.mkpath(runtimedir + "/logs");
database->logfilename = QDateTime::currentDateTime().toString("yyyyMMdd_hhmmss") + "_v" + VERSION + ".log";
logfile = new QFile(runtimedir + "/logs/" + database->logfilename);
logfile->open(QIODevice::WriteOnly | QIODevice::Text);
QObject::connect(qApp, &QCoreApplication::aboutToQuit, [&]()
{
if(logfile)
{
logfile -> close();
logfile -> deleteLater();
logfile = nullptr;
} });
}
QTextStream logout(logfile);
logout << OutMsg;
}
int main(int argc, char *argv[])
{
QCoreApplication::setOrganizationName("wgsylcl");
QCoreApplication::setApplicationName("memory");
MemoryApplication app(argc, argv);
qInstallMessageHandler(logmessagehander);
qDebug() << "Hello memory!";
qDebug() << "Run at " << QDateTime::currentDateTime().toString("yyyy-MM-dd hh-mm-ss") << "!";
#ifdef Q_OS_WIN
SetUnhandledExceptionFilter(MyUnhandledExceptionFilter);
#endif
return app.exec();
}