Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qdebugmessageservice.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant
4
5
#
include
"qdebugmessageservice.h"
6
7
#
include
<
private
/
qqmldebugconnector_p
.
h
>
8
#
include
<
private
/
qversionedpacket_p
.
h
>
9
10
QT_BEGIN_NAMESPACE
11
12
using
QQmlDebugPacket = QVersionedPacket<QQmlDebugConnector>;
13
14
void
DebugMessageHandler
(QtMsgType type,
const
QMessageLogContext &ctxt,
15
const
QString &buf)
16
{
17
if
(QDebugMessageServiceImpl *service = QQmlDebugConnector::service<QDebugMessageServiceImpl>())
18
service->sendDebugMessage(type, ctxt, buf);
19
}
20
21
QDebugMessageServiceImpl::QDebugMessageServiceImpl(QObject *parent) :
22
QDebugMessageService(2, parent), oldMsgHandler(
nullptr
),
23
prevState(QQmlDebugService::NotConnected)
24
{
25
// don't execute stateChanged() in parallel
26
QMutexLocker lock(&initMutex);
27
timer.start();
28
if
(state() == Enabled) {
29
oldMsgHandler = qInstallMessageHandler(DebugMessageHandler);
30
prevState = Enabled;
31
}
32
}
33
34
QDebugMessageServiceImpl::~QDebugMessageServiceImpl()
35
{
36
if
(oldMsgHandler)
37
restoreOldMessageHandler();
38
}
39
40
void
QDebugMessageServiceImpl::sendDebugMessage(QtMsgType type,
41
const
QMessageLogContext &ctxt,
42
const
QString &buf)
43
{
44
//We do not want to alter the message handling mechanism
45
//We just eavesdrop and forward the messages to a port
46
//only if a client is connected to it.
47
QQmlDebugPacket ws;
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();
51
52
emit messageToClient(name(), ws.data());
53
if
(oldMsgHandler)
54
(*oldMsgHandler)(type, ctxt, buf);
55
}
56
57
void
QDebugMessageServiceImpl::stateChanged(State state)
58
{
59
QMutexLocker lock(&initMutex);
60
61
if
(state != Enabled && prevState == Enabled)
62
restoreOldMessageHandler();
63
else
if
(state == Enabled && prevState != Enabled)
64
oldMsgHandler = qInstallMessageHandler(DebugMessageHandler);
65
66
prevState = state;
67
}
68
69
void
QDebugMessageServiceImpl::restoreOldMessageHandler()
70
{
71
QtMessageHandler handler = qInstallMessageHandler(oldMsgHandler);
72
73
// has our handler been overwritten in between?
74
// In that case, leave the other one alone and try again on destruction.
75
if
(handler == DebugMessageHandler)
76
oldMsgHandler =
nullptr
;
77
else
78
qInstallMessageHandler(handler);
79
}
80
81
void
QDebugMessageServiceImpl::synchronizeTime(
const
QElapsedTimer &otherTimer)
82
{
83
QMutexLocker lock(&initMutex);
84
timer = otherTimer;
85
}
86
87
QT_END_NAMESPACE
88
89
#
include
"moc_qdebugmessageservice.cpp"
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
DebugMessageHandler
void DebugMessageHandler(QtMsgType type, const QMessageLogContext &ctxt, const QString &buf)
Definition
qdebugmessageservice.cpp:14
qtdeclarative
src
plugins
qmltooling
qmldbg_messages
qdebugmessageservice.cpp
Generated on
for Qt by
1.18.0