Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmldebugconnector.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
8#include <QtCore/QPluginLoader>
9#include <QtCore/QCborArray>
10#include <QtCore/QCoreApplication>
11#include <QtCore/QDir>
12#include <QtCore/QDebug>
13#include <QtCore/QDataStream>
14
15#include <private/qcoreapplication_p.h>
16#include <private/qqmlengine_p.h>
17
19
20// Connectors. We could add more plugins here, and distinguish by arguments to instance()
21Q_QML_DEBUG_PLUGIN_LOADER(QQmlDebugConnector)
22
23// Services
24Q_QML_DEBUG_PLUGIN_LOADER(QQmlDebugService)
25
26int QQmlDebugConnector::s_dataStreamVersion = QDataStream::Qt_4_7;
27
33
35 {
36 if (qApp) {
37 QCoreApplicationPrivate *appD =
38 static_cast<QCoreApplicationPrivate*>(QObjectPrivate::get(qApp));
39 if (appD)
40 arguments = appD->qmljsDebugArgumentsString();
41 }
42 }
43};
44
45Q_GLOBAL_STATIC(QQmlDebugConnectorParams, qmlDebugConnectorParams)
46
47void QQmlDebugConnector::setPluginKey(const QString &key)
48{
49 QQmlDebugConnectorParams *params = qmlDebugConnectorParams();
50 if (params && params->pluginKey != key) {
51 if (params->instance)
52 qWarning() << "QML debugger: Cannot set plugin key after loading the plugin.";
53 else
54 params->pluginKey = key;
55 }
56}
57
58void QQmlDebugConnector::setServices(const QStringList &services)
59{
60 QQmlDebugConnectorParams *params = qmlDebugConnectorParams();
61 if (params)
62 params->services = services;
63}
64
65QString QQmlDebugConnector::commandLineArguments()
66{
67 QQmlDebugConnectorParams *params = qmlDebugConnectorParams();
68 if (!params)
69 return QString();
70 return params->arguments;
71}
72
73QQmlDebugConnector *QQmlDebugConnector::instance()
74{
75 QQmlDebugConnectorParams *params = qmlDebugConnectorParams();
76 if (!params)
77 return nullptr;
78
79 if (!QQmlEnginePrivate::qml_debugging_enabled.load(std::memory_order_relaxed)) {
80 if (!params->arguments.isEmpty()) {
81 qWarning().noquote() << QString::fromLatin1(
82 "QML Debugger: Ignoring \"-qmljsdebugger=%1\". Debugging "
83 "has not been enabled.").arg(params->arguments);
84 params->arguments.clear();
85 }
86 return nullptr;
87 }
88
89 if (!params->instance) {
90 if (!params->pluginKey.isEmpty()) {
91 params->instance = loadQQmlDebugConnector(params->pluginKey);
92 } else if (params->arguments.isEmpty()) {
93 return nullptr; // no explicit class name given and no command line arguments
94 } else if (params->arguments.startsWith(QLatin1String("connector:"))) {
95 static const int connectorBegin = int(strlen("connector:"));
96
97 int connectorEnd = params->arguments.indexOf(QLatin1Char(','), connectorBegin);
98 if (connectorEnd == -1)
99 connectorEnd = params->arguments.size();
100
101 params->instance = loadQQmlDebugConnector(params->arguments.mid(
102 connectorBegin,
103 connectorEnd - connectorBegin));
104 } else {
105 params->instance = loadQQmlDebugConnector(
106 params->arguments.startsWith(QLatin1String("native")) ?
107 QStringLiteral("QQmlNativeDebugConnector") :
108 QStringLiteral("QQmlDebugServer"));
109 }
110
111 if (params->instance) {
112 const auto metaData = metaDataForQQmlDebugService();
113 for (const QPluginParsedMetaData &md : metaData) {
114 const auto keys = md.value(QtPluginMetaDataKeys::MetaData).toMap()
115 .value(QLatin1String("Keys")).toArray();
116 for (const QCborValue key : keys) {
117 QString keyString = key.toString();
118 if (params->services.isEmpty() || params->services.contains(keyString))
119 loadQQmlDebugService(keyString);
120 }
121 }
122 }
123 }
124
125 return params->instance;
126}
127
128QQmlDebugConnectorFactory::~QQmlDebugConnectorFactory()
129{
130 // This is triggered when the plugin is unloaded.
131 QQmlDebugConnectorParams *params = qmlDebugConnectorParams();
132 if (params) {
133 params->pluginKey.clear();
134 params->arguments.clear();
135 params->services.clear();
136 delete params->instance;
137 params->instance = nullptr;
138 }
139}
140
141QT_END_NAMESPACE
142
143#include "moc_qqmldebugconnector_p.cpp"
Combined button and popup list for selecting options.
#define Q_QML_DEBUG_PLUGIN_LOADER(interfaceName)
QQmlDebugConnector * instance