20QDebugMessageServiceImpl::QDebugMessageServiceImpl(QObject *parent) :
21 QDebugMessageService(2, parent), oldMsgHandler(
nullptr),
22 prevState(QQmlDebugService::NotConnected)
25 QMutexLocker lock(&initMutex);
27 if (state() == Enabled) {
28 oldMsgHandler = qInstallMessageHandler(DebugMessageHandler);
39void QDebugMessageServiceImpl::sendDebugMessage(QtMsgType type,
40 const QMessageLogContext &ctxt,
47 ws << QByteArray(
"MESSAGE") <<
int(type) << buf.toUtf8();
48 ws << QByteArray(ctxt.file) << ctxt.line << QByteArray(ctxt.function);
49 ws << QByteArray(ctxt.category) << timer.nsecsElapsed();
51 emit messageToClient(name(), ws.data());
53 (*oldMsgHandler)(type, ctxt, buf);
56void QDebugMessageServiceImpl::stateChanged(State state)
58 QMutexLocker lock(&initMutex);
60 if (state != Enabled && prevState == Enabled)
61 restoreOldMessageHandler();
62 else if (state == Enabled && prevState != Enabled)
63 oldMsgHandler = qInstallMessageHandler(DebugMessageHandler);