Show the type and address of QObjects in debug output.
authorStephen Kelly <stephen.kelly@kdab.com>
Sun, 15 Apr 2012 23:17:00 +0000 (01:17 +0200)
committerQt by Nokia <qt-info@nokia.com>
Mon, 16 Apr 2012 09:35:44 +0000 (11:35 +0200)
Change-Id: I9f44ab80a6fb763adc9cbaf47de8e1b97212332d
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
src/corelib/kernel/qvariant.cpp
tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp

index 654170f..82e0435 100644 (file)
@@ -834,7 +834,13 @@ static bool customConvert(const QVariant::Private *, int, void *, bool *ok)
 }
 
 #if !defined(QT_NO_DEBUG_STREAM)
-static void customStreamDebug(QDebug, const QVariant &) {}
+static void customStreamDebug(QDebug dbg, const QVariant &variant) {
+#ifndef QT_BOOTSTRAPPED
+    QMetaType::TypeFlags flags = QMetaType::typeFlags(variant.userType());
+    if (flags & QMetaType::PointerToQObject)
+        dbg.nospace() << variant.value<QObject*>();
+#endif
+}
 #endif
 
 const QVariant::Handler qt_custom_variant_handler = {
index 1e382dd..6a6460d 100644 (file)
@@ -3666,6 +3666,11 @@ protected:
             // Chars insert '\0' into the qdebug stream, it is not possible to find a real string length
             return;
         }
+        if (QMetaType::typeFlags(currentId) & QMetaType::PointerToQObject) {
+            QByteArray currentName = QMetaType::typeName(currentId);
+            currentName.chop(1);
+            ok &= (msg.contains(", " + currentName) || msg.contains(", 0x0"));
+        }
         ok &= msg.endsWith(") ");
         QVERIFY2(ok, (QString::fromLatin1("Message is not correctly finished: '") + msg + '\'').toLatin1().constData());
 
@@ -3694,6 +3699,7 @@ void tst_QVariant::debugStream_data()
     QTest::newRow("CustomStreamableClass") << QVariant(qMetaTypeId<CustomStreamableClass>(), 0) << qMetaTypeId<CustomStreamableClass>();
     QTest::newRow("MyClass") << QVariant(qMetaTypeId<MyClass>(), 0) << qMetaTypeId<MyClass>();
     QTest::newRow("InvalidVariant") << QVariant() << int(QMetaType::UnknownType);
+    QTest::newRow("CustomQObject") << QVariant::fromValue(this) << qMetaTypeId<tst_QVariant*>();
 }
 
 void tst_QVariant::debugStream()