Show the type and address of QObjects in debug output.

Change-Id: I9f44ab80a6fb763adc9cbaf47de8e1b97212332d
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
This commit is contained in:
Stephen Kelly 2012-04-16 01:17:00 +02:00 committed by Qt by Nokia
parent d037d25c3d
commit 77fd8fd997
2 changed files with 13 additions and 1 deletions

View 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 = {

View 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()