21QDebugMessageServiceImpl::QDebugMessageServiceImpl(QObject *parent) :
22 QDebugMessageService(2, parent), oldMsgHandler(
nullptr),
23 prevState(QQmlDebugService::NotConnected)
26 QMutexLocker lock(&initMutex);
28 if (state() == Enabled) {
29 oldMsgHandler = qInstallMessageHandler(DebugMessageHandler);
40void QDebugMessageServiceImpl::sendDebugMessage(QtMsgType type,
41 const QMessageLogContext &ctxt,
48 ws << QByteArray(
"MESSAGE") <<
int(type) << buf.toUtf8();
49 ws << QByteArray(ctxt.file) << ctxt.line << QByteArray(ctxt.function);
50 ws << QByteArray(ctxt.category) << timer.nsecsElapsed();
52 emit messageToClient(name(), ws.data());
54 (*oldMsgHandler)(type, ctxt, buf);
57void QDebugMessageServiceImpl::stateChanged(State state)
59 QMutexLocker lock(&initMutex);
61 if (state != Enabled && prevState == Enabled)
62 restoreOldMessageHandler();
63 else if (state == Enabled && prevState != Enabled)
64 oldMsgHandler = qInstallMessageHandler(DebugMessageHandler);