diff options
author | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2015-12-01 15:50:15 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2016-01-07 16:25:16 +0000 |
commit | 39d1e93b675cc94708e5f727699fc6b3a290bda8 (patch) | |
tree | 962b9c77c86c3aebc0547a1f970e312145115269 /src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp | |
parent | eae5a20b099450985442c70186fd7a7be442f133 (diff) |
V4 Debugger: If no context is given inject the QML context
The user generally expects QML "root" objects to be in a "global"
scope. Or at least that makes debugging a lot easier. By opening a
WithContext with the relevant objects we can simulate that.
Task-number: QTCREATORBUG-14931
Change-Id: I89af0560803b2c54a35f08e9fd659e65fb937cb9
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp')
-rw-r--r-- | src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp index ac46905f1c..78cb2be8d3 100644 --- a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp +++ b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp @@ -39,6 +39,9 @@ #include <private/qv4identifier_p.h> #include <private/qv4runtime_p.h> +#include <private/qqmlcontext_p.h> +#include <private/qqmlengine_p.h> + #include <QtCore/qjsonarray.h> #include <QtCore/qjsonobject.h> @@ -352,6 +355,17 @@ QJsonObject QV4DataCollector::collectAsJson(const QString &name, const QV4::Scop void ValueLookupJob::run() { + // Open a QML context if we don't have one, yet. We might run into QML objects when looking up + // refs and that will crash without a valid QML context. Mind that engine->qmlContext() is only + // set if the engine is currently executing QML code. + QScopedPointer<QObject> scopeObject; + QV4::ExecutionEngine *engine = collector->engine(); + if (engine->qmlEngine() && !engine->qmlContext()) { + scopeObject.reset(new QObject); + engine->pushContext(engine->currentContext->newQmlContext( + QQmlContextData::get(engine->qmlEngine()->rootContext()), + scopeObject.data())); + } foreach (const QJsonValue &handle, handles) { QV4DataCollector::Ref ref = handle.toInt(); if (!collector->isValidRef(ref)) { @@ -361,6 +375,8 @@ void ValueLookupJob::run() result[QString::number(ref)] = collector->lookupRef(ref); } collectedRefs = collector->flushCollectedRefs(); + if (scopeObject) + engine->popContext(); } const QString &ValueLookupJob::exceptionMessage() const |