diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2018-05-25 16:59:42 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2018-05-25 15:21:32 +0000 |
commit | 9a44e3b6ca81f0e84d774a95e45b449b5d4cb583 (patch) | |
tree | e57fe07bfbfc8e64fd2f9214e9ddd5d47b3d9136 /src/plugins/qmltooling/qmldbg_debugger/qqmlenginedebugservice.cpp | |
parent | 71688bab1b7abf64ae840dff887aa501e83d5acc (diff) |
QML Debugger: Don't crash when encoding JSON data
Apparently QVariant::save cannot deal with QJsonObject and friends.
Transform them into QVariants before sending them over the wire.
Task-number: QTBUG-68474
Change-Id: I8fc9fade4915c2b40f8d16aea51ea6ff65247dc1
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/plugins/qmltooling/qmldbg_debugger/qqmlenginedebugservice.cpp')
-rw-r--r-- | src/plugins/qmltooling/qmldbg_debugger/qqmlenginedebugservice.cpp | 63 |
1 files changed, 37 insertions, 26 deletions
diff --git a/src/plugins/qmltooling/qmldbg_debugger/qqmlenginedebugservice.cpp b/src/plugins/qmltooling/qmldbg_debugger/qqmlenginedebugservice.cpp index d008b86a78..17bae6d695 100644 --- a/src/plugins/qmltooling/qmldbg_debugger/qqmlenginedebugservice.cpp +++ b/src/plugins/qmltooling/qmldbg_debugger/qqmlenginedebugservice.cpp @@ -55,6 +55,11 @@ #include <QtCore/qdebug.h> #include <QtCore/qmetaobject.h> #include <QtCore/qfileinfo.h> +#include <QtCore/qjsonvalue.h> +#include <QtCore/qjsonobject.h> +#include <QtCore/qjsonarray.h> +#include <QtCore/qjsondocument.h> + #include <private/qmetaobject_p.h> #include <private/qqmldebugconnector_p.h> #include <private/qversionedpacket_p.h> @@ -211,34 +216,40 @@ QVariant QQmlEngineDebugServiceImpl::valueContents(QVariant value) const return contents; } - if (QQmlValueTypeFactory::isValueType(userType)) { - switch (userType) { - case QMetaType::QRect: - case QMetaType::QRectF: - case QMetaType::QPoint: - case QMetaType::QPointF: - case QMetaType::QSize: - case QMetaType::QSizeF: - 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()"); - if (toStringIndex != -1) { - QMetaMethod mm = mo->method(toStringIndex); - QString s; - if (mm.invokeOnGadget(value.data(), Q_RETURN_ARG(QString, s))) - return s; + switch (userType) { + case QMetaType::QRect: + case QMetaType::QRectF: + case QMetaType::QPoint: + case QMetaType::QPointF: + case QMetaType::QSize: + case QMetaType::QSizeF: + case QMetaType::QFont: + // Don't call the toString() method on those. The stream operators are better. + return value; + case QMetaType::QJsonValue: + return value.toJsonValue().toVariant(); + case QMetaType::QJsonObject: + return value.toJsonObject().toVariantMap(); + case QMetaType::QJsonArray: + return value.toJsonArray().toVariantList(); + case QMetaType::QJsonDocument: + return value.toJsonDocument().toVariant(); + default: + if (QQmlValueTypeFactory::isValueType(userType)) { + const QMetaObject *mo = QQmlValueTypeFactory::metaObjectForMetaType(userType); + if (mo) { + int toStringIndex = mo->indexOfMethod("toString()"); + if (toStringIndex != -1) { + QMetaMethod mm = mo->method(toStringIndex); + 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; + // We expect all QML value types to either have a toString() method or stream operators + return value; + } } if (QQmlMetaType::isQObject(userType)) { |