From 66f8b97f5ea4a8d196f908fae78d2b68cfab32cf Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 12 Dec 2017 14:35:13 +0100 Subject: QQmlEngineDebugService: Actually call value types' toString() method QML value types generally are Q_GADGETs, but the userType we see there is the wrapped class's type, which doesn't have to be a gadget. So, the toString() method was rarely called, and a model index would still crash the debug service. Change-Id: I63778953eb9d2fc60113c11057da3047fc75a9bd Reviewed-by: Simon Hausmann --- .../qmldbg_debugger/qqmlenginedebugservice.cpp | 19 +++++++++++++++---- .../tst_qqmlenginedebugservice.cpp | 3 ++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/plugins/qmltooling/qmldbg_debugger/qqmlenginedebugservice.cpp b/src/plugins/qmltooling/qmldbg_debugger/qqmlenginedebugservice.cpp index d2cf7dc57f..cbce99956d 100644 --- a/src/plugins/qmltooling/qmldbg_debugger/qqmlenginedebugservice.cpp +++ b/src/plugins/qmltooling/qmldbg_debugger/qqmlenginedebugservice.cpp @@ -209,19 +209,30 @@ QVariant QQmlEngineDebugServiceImpl::valueContents(QVariant value) const } if (QQmlValueTypeFactory::isValueType(userType)) { + switch (userType) { + case QMetaType::QRect: + case QMetaType::QRectF: + case QMetaType::QPoint: + case QMetaType::QPointF: + case QMetaType::QFont: + // Don't call the toString() method on those. The stream operators are better. + return value; + default: + break; + } + const QMetaObject *mo = QQmlValueTypeFactory::metaObjectForMetaType(userType); if (mo) { - int toStringIndex = mo->indexOfMethod("toString"); + int toStringIndex = mo->indexOfMethod("toString()"); if (toStringIndex != -1) { QMetaMethod mm = mo->method(toStringIndex); - QMetaType info(userType); QString s; - if (info.flags() & QMetaType::IsGadget - && mm.invokeOnGadget(value.data(), Q_RETURN_ARG(QString, s))) + if (mm.invokeOnGadget(value.data(), Q_RETURN_ARG(QString, s))) return s; } } + // We expect all QML value types to either have a toString() method or stream operators return value; } diff --git a/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp b/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp index 57e95f7b89..6d31ff9219 100644 --- a/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp +++ b/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp @@ -896,7 +896,8 @@ void tst_QQmlEngineDebugService::queryObjectWithNonStreamableTypes() QmlDebugObjectReference obj = m_dbg->object(); QVERIFY(!obj.className.isEmpty()); - QCOMPARE(findProperty(obj.properties, "modelIndex").value, QVariant()); + QCOMPARE(findProperty(obj.properties, "modelIndex").value, + QVariant(QLatin1String("QModelIndex()"))); } -- cgit v1.2.3