-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMsgHandlerWapper.cpp
46 lines (39 loc) · 1.3 KB
/
MsgHandlerWapper.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
#include "MsgHandlerWapper.h"
#include <QtCore/QMetaType>
#include <QtCore/QMutex>
#include <QtCore/QMutexLocker>
#include <QtCore/QCoreApplication>
/*
connect(MsgHandlerWapper::instance(),
SIGNAL(message(QtMsgType, const QMessageLogContext &, const QString &)),
this, SLOT(outputMessage(QtMsgType, const QMessageLogContext &, const QString &)));
void outputMessage(QtMsgType, const QMessageLogContext &, const QString & msg)
{
ui->textBrowser->append(msg);
}
*/
void static msgHandlerFunction(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
emit MsgHandlerWapper::instance()->message(type, context, msg);
// QMetaObject::invokeMethod(MsgHandlerWapper::instance(), "message"
// , Q_ARG(QtMsgType, type), Q_ARG(QMessageLogContext, context)
// , Q_ARG(QString, msg));
}
MsgHandlerWapper * MsgHandlerWapper::m_instance = 0;
MsgHandlerWapper * MsgHandlerWapper::instance()
{
static QMutex mutex;
if (!m_instance)
{
QMutexLocker locker(&mutex);
if (!m_instance)
m_instance = new MsgHandlerWapper;
}
return m_instance;
}
MsgHandlerWapper::MsgHandlerWapper()
:QObject(qApp)
{
qRegisterMetaType<QtMsgType>("QtMsgType");
qInstallMessageHandler(msgHandlerFunction);
}