aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@theqtcompany.com>2016-03-17 16:17:15 +0100
committerUlf Hermann <ulf.hermann@theqtcompany.com>2016-03-26 12:22:24 +0000
commit19d16b33ad2bf7312e2470f31f43fa1acf92f088 (patch)
tree53fa6abe329bf37e8a2f4f7a6eb872aaced74456
parent5ce1b892a14a9940e4c8abbbed69bc011394c617 (diff)
Allow custom debug connectors
Expose a generic method for loading connector plugins in QQmlDebuggingEnabler and don't insist on the two known ones when actually loading them. This allows third-party connector plugins to be loaded, for example to pass QML trace events to a generic tracing library. Change-Id: I4f66dfabdbd0c3aff3676f7e2591e0a6c42f8f7f Reviewed-by: hjk <hjk@theqtcompany.com> Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
-rw-r--r--src/qml/debugger/qqmldebug.cpp52
-rw-r--r--src/qml/debugger/qqmldebug.h3
-rw-r--r--src/qml/debugger/qqmldebugconnector.cpp13
3 files changed, 36 insertions, 32 deletions
diff --git a/src/qml/debugger/qqmldebug.cpp b/src/qml/debugger/qqmldebug.cpp
index 64a951d53b..9276bd0544 100644
--- a/src/qml/debugger/qqmldebug.cpp
+++ b/src/qml/debugger/qqmldebug.cpp
@@ -134,22 +134,11 @@ void QQmlDebuggingEnabler::setServices(const QStringList &services)
*/
bool QQmlDebuggingEnabler::startTcpDebugServer(int port, StartMode mode, const QString &hostName)
{
-#ifndef QQML_NO_DEBUG_PROTOCOL
- QQmlDebugConnector::setPluginKey(QLatin1String("QQmlDebugServer"));
- QQmlDebugConnector *connector = QQmlDebugConnector::instance();
- if (connector) {
- QVariantHash configuration;
- configuration[QLatin1String("portFrom")] = configuration[QLatin1String("portTo")] = port;
- configuration[QLatin1String("block")] = (mode == WaitForClient);
- configuration[QLatin1String("hostAddress")] = hostName;
- return connector->open(configuration);
- }
-#else
- Q_UNUSED(port);
- Q_UNUSED(mode);
- Q_UNUSED(hostName);
-#endif
- return false;
+ QVariantHash configuration;
+ configuration[QLatin1String("portFrom")] = configuration[QLatin1String("portTo")] = port;
+ configuration[QLatin1String("block")] = (mode == WaitForClient);
+ configuration[QLatin1String("hostAddress")] = hostName;
+ return startDebugConnector(QLatin1String("QQmlDebugServer"), configuration);
}
/*!
@@ -164,18 +153,33 @@ bool QQmlDebuggingEnabler::startTcpDebugServer(int port, StartMode mode, const Q
*/
bool QQmlDebuggingEnabler::connectToLocalDebugger(const QString &socketFileName, StartMode mode)
{
+ QVariantHash configuration;
+ configuration[QLatin1String("fileName")] = socketFileName;
+ configuration[QLatin1String("block")] = (mode == WaitForClient);
+ return startDebugConnector(QLatin1String("QQmlDebugServer"), configuration);
+}
+
+/*!
+ * \since 5.7
+ *
+ * Enables debugging for QML engines created after calling this function. A debug connector plugin
+ * specified by \a pluginName will be loaded and started using the given \a configuration. Supported
+ * configuration entries and their semantics depend on the plugin being loaded. You can only start
+ * one debug connector at a time. A debug connector may have already been started if the
+ * -qmljsdebugger= command line argument was given. This method returns \c true if a new debug
+ * connector was successfully started, or \c false otherwise.
+ */
+bool QQmlDebuggingEnabler::startDebugConnector(const QString &pluginName,
+ const QVariantHash &configuration)
+{
#ifndef QQML_NO_DEBUG_PROTOCOL
- QQmlDebugConnector::setPluginKey(QLatin1String("QQmlDebugServer"));
+ QQmlDebugConnector::setPluginKey(pluginName);
QQmlDebugConnector *connector = QQmlDebugConnector::instance();
- if (connector) {
- QVariantHash configuration;
- configuration[QLatin1String("fileName")] = socketFileName;
- configuration[QLatin1String("block")] = (mode == WaitForClient);
+ if (connector)
return connector->open(configuration);
- }
#else
- Q_UNUSED(fileName);
- Q_UNUSED(mode);
+ Q_UNUSED(pluginName);
+ Q_UNUSED(configuration);
#endif
return false;
}
diff --git a/src/qml/debugger/qqmldebug.h b/src/qml/debugger/qqmldebug.h
index eebebefe62..660b9e4d46 100644
--- a/src/qml/debugger/qqmldebug.h
+++ b/src/qml/debugger/qqmldebug.h
@@ -42,6 +42,7 @@
#include <QtQml/qtqmlglobal.h>
#include <QtCore/qstring.h>
+#include <QtCore/qvariant.h>
QT_BEGIN_NAMESPACE
@@ -65,6 +66,8 @@ struct Q_QML_EXPORT QQmlDebuggingEnabler
const QString &hostName = QString());
static bool connectToLocalDebugger(const QString &socketFileName,
StartMode mode = DoNotWaitForClient);
+ static bool startDebugConnector(const QString &pluginName,
+ const QVariantHash &configuration = QVariantHash());
};
// Execute code in constructor before first QQmlEngine is instantiated
diff --git a/src/qml/debugger/qqmldebugconnector.cpp b/src/qml/debugger/qqmldebugconnector.cpp
index 6edd28ea01..e6d1a218ad 100644
--- a/src/qml/debugger/qqmldebugconnector.cpp
+++ b/src/qml/debugger/qqmldebugconnector.cpp
@@ -127,18 +127,15 @@ QQmlDebugConnector *QQmlDebugConnector::instance()
}
if (!params->instance) {
- const QString serverConnector = QStringLiteral("QQmlDebugServer");
- const QString nativeConnector = QStringLiteral("QQmlNativeDebugConnector");
- const bool isNative = params->arguments.startsWith(QLatin1String("native"));
if (!params->pluginKey.isEmpty()) {
- if (params->pluginKey == serverConnector || params->pluginKey == nativeConnector)
- params->instance = loadQQmlDebugConnector(params->pluginKey);
- else
- return 0; // We cannot load anything else, yet
+ params->instance = loadQQmlDebugConnector(params->pluginKey);
} else if (params->arguments.isEmpty()) {
return 0; // no explicit class name given and no command line arguments
} else {
- params->instance = loadQQmlDebugConnector(isNative ? nativeConnector : serverConnector);
+ params->instance = loadQQmlDebugConnector(
+ params->arguments.startsWith(QLatin1String("native")) ?
+ QStringLiteral("QQmlNativeDebugConnector") :
+ QStringLiteral("QQmlDebugServer"));
}
if (params->instance) {