aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/debugger/qqmlenginedebugservice.cpp11
-rw-r--r--tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.cpp20
-rw-r--r--tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.h3
-rw-r--r--tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp50
4 files changed, 82 insertions, 2 deletions
diff --git a/src/qml/debugger/qqmlenginedebugservice.cpp b/src/qml/debugger/qqmlenginedebugservice.cpp
index b095e8f9bb..21e9d67305 100644
--- a/src/qml/debugger/qqmlenginedebugservice.cpp
+++ b/src/qml/debugger/qqmlenginedebugservice.cpp
@@ -499,11 +499,20 @@ void QQmlEngineDebugService::processMessage(const QByteArray &message)
QString expr;
ds >> objectId >> expr;
+ int engineId = -1;
+ if (!ds.atEnd())
+ ds >> engineId;
QObject *object = QQmlDebugService::objectForId(objectId);
QQmlContext *context = qmlContext(object);
+ if (!context) {
+ QQmlEngine *engine = qobject_cast<QQmlEngine *>(
+ QQmlDebugService::objectForId(engineId));
+ if (engine && m_engines.contains(engine))
+ context = engine->rootContext();
+ }
QVariant result;
- if (object && context) {
+ if (context) {
QQmlExpression exprObj(context, object, expr);
bool undefined = false;
QVariant value = exprObj.evaluate(&undefined);
diff --git a/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.cpp b/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.cpp
index 0c5dfddffa..eb04fb2c2e 100644
--- a/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.cpp
+++ b/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.cpp
@@ -241,7 +241,25 @@ quint32 QQmlEngineDebugClient::queryExpressionResult(
m_exprResult = QVariant();
quint32 id;
*success = false;
- if (state() == QQmlDebugClient::Enabled && objectDebugId != -1) {
+ if (state() == QQmlDebugClient::Enabled) {
+ id = getId();
+ QByteArray message;
+ QDataStream ds(&message, QIODevice::WriteOnly);
+ ds << QByteArray("EVAL_EXPRESSION") << id << objectDebugId << expr
+ << engines()[0].debugId;
+ sendMessage(message);
+ *success = true;
+ }
+ return id;
+}
+
+quint32 QQmlEngineDebugClient::queryExpressionResultBC(
+ int objectDebugId, const QString &expr, bool *success)
+{
+ m_exprResult = QVariant();
+ quint32 id;
+ *success = false;
+ if (state() == QQmlDebugClient::Enabled) {
id = getId();
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
diff --git a/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.h b/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.h
index 62f9b15824..34d4e971a1 100644
--- a/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.h
+++ b/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.h
@@ -197,6 +197,9 @@ public:
quint32 queryExpressionResult(int objectDebugId,
const QString &expr,
bool *success);
+ quint32 queryExpressionResultBC(int objectDebugId,
+ const QString &expr,
+ bool *success);
quint32 setBindingForObject(int objectDebugId, const QString &propertyName,
const QVariant &bindingExpression,
bool isLiteralValue,
diff --git a/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp b/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp
index cc1193b0f1..17b22b43a2 100644
--- a/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp
+++ b/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp
@@ -120,6 +120,9 @@ private slots:
void queryObject_data();
void queryExpressionResult();
void queryExpressionResult_data();
+ void queryExpressionResultInRootContext();
+ void queryExpressionResultBC();
+ void queryExpressionResultBC_data();
void setBindingForObject();
void setMethodBody();
@@ -721,6 +724,53 @@ void tst_QQmlEngineDebugService::queryExpressionResult_data()
QTest::newRow("varObjMap") << "varObjMap" << qVariantFromValue(map);
}
+void tst_QQmlEngineDebugService::queryExpressionResultInRootContext()
+{
+ bool success;
+ const QString exp = QLatin1String("1");
+ m_dbg->queryExpressionResult(-1, exp, &success);
+ QVERIFY(success);
+ QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result())));
+
+ QCOMPARE(m_dbg->resultExpr().toString(), exp);
+}
+
+void tst_QQmlEngineDebugService::queryExpressionResultBC()
+{
+ QFETCH(QString, expr);
+ QFETCH(QVariant, result);
+
+ int objectId = findRootObject().debugId;
+
+ bool success;
+
+ QQmlEngineDebugClient *unconnected = new QQmlEngineDebugClient(0);
+ unconnected->queryExpressionResultBC(objectId, expr, &success);
+ QVERIFY(!success);
+ delete unconnected;
+
+ m_dbg->queryExpressionResultBC(objectId, expr, &success);
+ QVERIFY(success);
+ QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result())));
+
+ QCOMPARE(m_dbg->resultExpr(), result);
+}
+
+void tst_QQmlEngineDebugService::queryExpressionResultBC_data()
+{
+ QTest::addColumn<QString>("expr");
+ QTest::addColumn<QVariant>("result");
+
+ QTest::newRow("width + 50") << "width + 50" << qVariantFromValue(60);
+ QTest::newRow("blueRect.width") << "blueRect.width" << qVariantFromValue(500);
+ QTest::newRow("bad expr") << "aeaef" << qVariantFromValue(QString("<undefined>"));
+ QTest::newRow("QObject*") << "varObj" << qVariantFromValue(QString("<unnamed object>"));
+ QTest::newRow("list of QObject*") << "varObjList" << qVariantFromValue(QString("<unknown value>"));
+ QVariantMap map;
+ map.insert(QLatin1String("rect"), QVariant(QLatin1String("<unnamed object>")));
+ QTest::newRow("varObjMap") << "varObjMap" << qVariantFromValue(map);
+}
+
void tst_QQmlEngineDebugService::setBindingForObject()
{
QmlDebugObjectReference rootObject = findRootObject();