-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
56 lines (52 loc) · 1.43 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 "mainwindow.h"
#include <QApplication>
#include <QtDebug>
#include <QFile>
#include <QTextStream>
#include <QDateTime>
QString filename;
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
void MessageHandlerToFile(QtMsgType type, const QMessageLogContext &, const QString & str)
{
const char * msg = str.toStdString().c_str();
#else
void MessageHandlerToFile(QtMsgType type, const char *msg)
{
#endif
QString txt;
switch (type) {
case QtDebugMsg:
txt = QString("Debug: %1").arg(msg);
break;
case QtWarningMsg:
txt = QString("Warning: %1").arg(msg);
break;
case QtCriticalMsg:
txt = QString("Critical: %1").arg(msg);
break;
case QtFatalMsg:
txt = QString("Fatal: %1").arg(msg);
break;
case QtInfoMsg:
txt = QString("Info: %1").arg(msg);
break;
}
QFile outFile(filename);
outFile.open(QIODevice::WriteOnly | QIODevice::Append);
QTextStream ts(&outFile);
ts << txt << endl;
}
int main( int argc, char * argv[] )
{
// QDateTime curdt = QDateTime::currentDateTime();
// filename = "./logs/"+curdt.toString(Qt::ISODate)+".txt";
//#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
// qInstallMessageHandler(MessageHandlerToFile);
//#else
// qInstallMsgHandler(MessageHandlerToFile);
//#endif
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}