Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
7#include <QtCore/QPluginLoader>
8#include <QtCore/QCborArray>
9#include <QtCore/QCoreApplication>
10#include <QtCore/QDir>
11#include <QtCore/QDebug>
12#include <QtCore/QDataStream>
13
14#include <private/qcoreapplication_p.h>
15#include <private/qqmlengine_p.h>
16
18
19// Connectors. We could add more plugins here, and distinguish by arguments to instance()
21
22// Services
24
25int QQmlDebugConnector::s_dataStreamVersion = QDataStream::Qt_4_7;
26
43
44Q_GLOBAL_STATIC(QQmlDebugConnectorParams, qmlDebugConnectorParams)
45
46void QQmlDebugConnector::setPluginKey(const QString &key)
47{
48 QQmlDebugConnectorParams *params = qmlDebugConnectorParams();
49 if (params && params->pluginKey != key) {
50 if (params->instance)
51 qWarning() << "QML debugger: Cannot set plugin key after loading the plugin.";
52 else
53 params->pluginKey = key;
54 }
55}
56
57void QQmlDebugConnector::setServices(const QStringList &services)
58{
59 QQmlDebugConnectorParams *params = qmlDebugConnectorParams();
60 if (params)
61 params->services = services;
62}
63
64QString QQmlDebugConnector::commandLineArguments()
65{
66 QQmlDebugConnectorParams *params = qmlDebugConnectorParams();
67 if (!params)
68 return QString();
69 return params->arguments;
70}
71
73{
74 QQmlDebugConnectorParams *params = qmlDebugConnectorParams();
75 if (!params)
76 return nullptr;
77
78 if (!QQmlEnginePrivate::qml_debugging_enabled.load(std::memory_order_relaxed)) {
79 if (!params->arguments.isEmpty()) {
80 qWarning().noquote() << QString::fromLatin1(
81 "QML Debugger: Ignoring \"-qmljsdebugger=%1\". Debugging "
82 "has not been enabled.").arg(params->arguments);
83 params->arguments.clear();
84 }
85 return nullptr;
86 }
87
88 if (!params->instance) {
89 if (!params->pluginKey.isEmpty()) {
90 params->instance = loadQQmlDebugConnector(params->pluginKey);
91 } else if (params->arguments.isEmpty()) {
92 return nullptr; // no explicit class name given and no command line arguments
93 } else if (params->arguments.startsWith(QLatin1String("connector:"))) {
94 static const int connectorBegin = int(strlen("connector:"));
95
96 int connectorEnd = params->arguments.indexOf(QLatin1Char(','), connectorBegin);
97 if (connectorEnd == -1)
98 connectorEnd = params->arguments.size();
99
100 params->instance = loadQQmlDebugConnector(params->arguments.mid(
101 connectorBegin,
102 connectorEnd - connectorBegin));
103 } else {
104 params->instance = loadQQmlDebugConnector(
105 params->arguments.startsWith(QLatin1String("native")) ?
106 QStringLiteral("QQmlNativeDebugConnector") :
107 QStringLiteral("QQmlDebugServer"));
108 }
109
110 if (params->instance) {
111 const auto metaData = metaDataForQQmlDebugService();
112 for (const QPluginParsedMetaData &md : metaData) {
113 const auto keys = md.value(QtPluginMetaDataKeys::MetaData).toMap()
114 .value(QLatin1String("Keys")).toArray();
115 for (const QCborValue key : keys) {
116 QString keyString = key.toString();
117 if (params->services.isEmpty() || params->services.contains(keyString))
118 loadQQmlDebugService(keyString);
119 }
120 }
121 }
122 }
123
124 return params->instance;
125}
126
127QQmlDebugConnectorFactory::~QQmlDebugConnectorFactory()
128{
129 // This is triggered when the plugin is unloaded.
130 QQmlDebugConnectorParams *params = qmlDebugConnectorParams();
131 if (params) {
132 params->pluginKey.clear();
133 params->arguments.clear();
134 params->services.clear();
135 delete params->instance;
136 params->instance = nullptr;
137 }
138}
139
141
142#include "moc_qqmldebugconnector_p.cpp"
std::vector< ObjCStrongReference< CBMutableService > > services
\inmodule QtCore\reentrant
Definition qcborvalue.h:47
static QObjectPrivate * get(QObject *o)
Definition qobject_p.h:150
static QQmlDebugConnector * instance()
static std::atomic< bool > qml_debugging_enabled
\qmltype QtObject \instantiates QObject \inqmlmodule QtQml
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5871
p1 load("image.bmp")
Combined button and popup list for selecting options.
#define qApp
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
#define qWarning
Definition qlogging.h:166
GLuint64 key
void ** params
#define Q_QML_DEBUG_PLUGIN_LOADER(interfaceName)
static QString keyString(int sym, QChar::Category category)
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define QStringLiteral(str)
QStringList keys
QObject::connect nullptr
\inmodule QtCore \reentrant
Definition qchar.h:18
QQmlDebugConnector * instance