diff options
author | Mårten Nordheim <marten.nordheim@qt.io> | 2018-11-06 14:55:47 +0100 |
---|---|---|
committer | Mårten Nordheim <marten.nordheim@qt.io> | 2018-11-08 14:34:02 +0000 |
commit | 6fecfdc769314162d6c909c9ae0a85631964883f (patch) | |
tree | e9cedbbb0b064b4ca0ec362456af2bc2d4dff0c0 /tests/auto/qml/qqmlconsole | |
parent | 52519c7955b941db13a1800daf7ffaf5eeeecad2 (diff) |
Use custom debug stream operator in console.log
Fallback for string-conversion was previously using hard-coded string
template mimicing QVariant. Just use QVariant's debug stream operator
which may include data from the contained type.
Change-Id: I8243ba6b04d842a895ac3234bb54f6a4eed849f1
Fixes: QTBUG-60057
Done-With: Jędrzej Nowacki <jedrzej.nowacki@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlconsole')
-rw-r--r-- | tests/auto/qml/qqmlconsole/data/logging.qml | 1 | ||||
-rw-r--r-- | tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp | 14 |
2 files changed, 15 insertions, 0 deletions
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); |