forked from jing332/xmly-downloader-qt5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
74 lines (65 loc) · 1.84 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
69
70
71
72
73
74
#include <QApplication>
#include <QDateTime>
#include <QDebug>
#include <QFile>
#include <QMetaType>
#include "appevent.h"
#include "cgoqt/cgo.h"
#include "cgoqt/xmlydownloader.h"
#include "ui/mainwindow.h"
//自定义消息处理函数
void myMessageOutput(QtMsgType type, const QMessageLogContext &context,
const QString &msg) {
QDateTime time = QDateTime::currentDateTime();
QString strTime = time.toString("yyyy-MM-dd hh:mm:ss");
QString strMessage =
QString("\033[31m[%1] %2:%3")
.arg(strTime)
.arg(QString(context.file).remove("\\xmly-downloader-qt5"))
.arg(context.line);
QString strMsg;
switch (type) {
case QtDebugMsg:
strMsg = QString(" [Debug] ");
break;
case QtInfoMsg:
strMsg = QString(" [Info] ");
break;
case QtWarningMsg:
strMsg = QString(" [Warning] ");
break;
case QtCriticalMsg:
strMsg = QString(" [Critical] ");
break;
case QtFatalMsg:
strMsg = QString(" [Fatal] ");
break;
default:
strMsg = QString(" [Err]");
break;
}
strMessage = strMessage.append(strMsg).append("\033[0m").append(msg);
//同时用系统原来的函数完成输出打印
FILE *device = stdout;
if (type > QtInfoMsg) {
device = stderr;
}
QTextStream outputStream(device);
outputStream << strMessage << Qt::endl;
outputStream.flush();
}
void OnUpdateFileLength(int id, long *contentLength, long *currentLength) {
emit AppEvent::getInstance()->UpdateFileLength(id, contentLength,
currentLength);
}
MainWindow *win;
int main(int argc, char *argv[]) {
#ifdef QT_DEBUG
qInstallMessageHandler(myMessageOutput);
#endif
CgoRegisterCallback(OnUpdateFileLength);
QApplication a(argc, argv);
win = new MainWindow();
win->show();
return a.exec();
}