aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/jsruntime/qv4variantobject.cpp13
-rw-r--r--tests/auto/qml/qjsengine/tst_qjsengine.cpp2
-rw-r--r--tests/auto/qml/qjsvalue/tst_qjsvalue.cpp2
-rw-r--r--tests/auto/qml/qqmlconsole/data/logging.qml1
-rw-r--r--tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp14
5 files changed, 25 insertions, 7 deletions
diff --git a/src/qml/jsruntime/qv4variantobject.cpp b/src/qml/jsruntime/qv4variantobject.cpp
index ef0877dbd0..e4d8bcaafc 100644
--- a/src/qml/jsruntime/qv4variantobject.cpp
+++ b/src/qml/jsruntime/qv4variantobject.cpp
@@ -138,11 +138,14 @@ ReturnedValue VariantPrototype::method_toString(const FunctionObject *b, const V
const VariantObject *o = thisObject->as<QV4::VariantObject>();
if (!o)
RETURN_UNDEFINED();
- QString result = o->d()->data().toString();
- if (result.isEmpty() && !o->d()->data().canConvert(QVariant::String)) {
- result = QLatin1String("QVariant(")
- + QLatin1String(o->d()->data().typeName())
- + QLatin1Char(')');
+ const QVariant variant = o->d()->data();
+ QString result = variant.toString();
+ if (result.isEmpty() && !variant.canConvert(QVariant::String)) {
+ QDebug dbg(&result);
+ dbg << variant;
+ // QDebug appends a space, we're not interested in continuing the stream so we chop it off.
+ // Can't use nospace() because it would affect the debug-stream operator of the variant.
+ result.chop(1);
}
return Encode(v4->newString(result));
}
diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
index 00c631141b..b75f069fab 100644
--- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp
+++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
@@ -500,7 +500,7 @@ void tst_QJSEngine::newVariant_valueOfToString()
QJSValue value = object.property("valueOf").callWithInstance(object);
QVERIFY(value.isObject());
QVERIFY(value.strictlyEquals(object));
- QCOMPARE(object.toString(), QString::fromLatin1("QVariant(QPoint)"));
+ QCOMPARE(object.toString(), QString::fromLatin1("QVariant(QPoint, QPoint(10,20))"));
}
}
diff --git a/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp b/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp
index f9718e3699..b58cd98d1e 100644
--- a/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp
+++ b/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp
@@ -405,7 +405,7 @@ void tst_QJSValue::toString()
// then fall back to "QVariant(typename)"
QJSValue variant = eng.toScriptValue(QPoint(10, 20));
QVERIFY(variant.isVariant());
- QCOMPARE(variant.toString(), QString::fromLatin1("QVariant(QPoint)"));
+ QCOMPARE(variant.toString(), QString::fromLatin1("QVariant(QPoint, QPoint(10,20))"));
variant = eng.toScriptValue(QUrl());
QVERIFY(variant.isVariant());
QVERIFY(variant.toString().isEmpty());
diff --git a/tests/auto/qml/qqmlconsole/data/logging.qml b/tests/auto/qml/qqmlconsole/data/logging.qml
index 0764ad7545..8ed2dd73a1 100644
--- a/tests/auto/qml/qqmlconsole/data/logging.qml
+++ b/tests/auto/qml/qqmlconsole/data/logging.qml
@@ -68,6 +68,7 @@ QtObject {
console.log(1, ["ping","pong"], new Object, 2);
console.log(contextStringListProperty);
+ console.log(customObject);
try {
console.log(exception);
diff --git a/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp b/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp
index 817ca0a257..f26eaa0817 100644
--- a/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp
+++ b/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp
@@ -51,6 +51,15 @@ private:
QQmlEngine engine;
};
+struct CustomObject {};
+
+QDebug operator<<(QDebug dbg, const CustomObject &)
+{
+ return dbg << "MY OBJECT";
+}
+
+Q_DECLARE_METATYPE(CustomObject)
+
void tst_qqmlconsole::logging()
{
QUrl testUrl = testFileUrl("logging.qml");
@@ -83,11 +92,16 @@ void tst_qqmlconsole::logging()
QTest::ignoreMessage(QtDebugMsg, "1 pong! [object Object]");
QTest::ignoreMessage(QtDebugMsg, "1 [ping,pong] [object Object] 2");
QTest::ignoreMessage(QtDebugMsg, "[Hello,World]");
+ QTest::ignoreMessage(QtDebugMsg, "QVariant(CustomObject, MY OBJECT)");
QScopedPointer<QQmlContext> loggingContext(new QQmlContext(engine.rootContext()));
QStringList stringList; stringList << QStringLiteral("Hello") << QStringLiteral("World");
loggingContext->setContextProperty("contextStringListProperty", stringList);
+ CustomObject customObject;
+ QVERIFY(QMetaType::registerDebugStreamOperator<CustomObject>());
+ loggingContext->setContextProperty("customObject", QVariant::fromValue(customObject));
+
QQmlComponent component(&engine, testUrl);
QScopedPointer<QObject> object(component.create(loggingContext.data()));
QVERIFY(object != nullptr);