diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2024-01-22 09:37:41 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2024-02-10 22:07:56 +0100 |
commit | a8c04721afd4457b4590db892bb246918dab1076 (patch) | |
tree | eb9ea22f12a3d2cf5f1d2b74fa6d4d3ee40cfbef | |
parent | 2c51a0bb7b71cba0d085281f7a588f750b06a8e4 (diff) |
Add virtual QObjectPrivate::writeToDebugStream
QObject by default writes class- and objectName to the debug stream,
but QObject subclasses might want to write different, or additional
information. Providing class-specific debug stream operators is not a
good solution for this, as it doesn't respect runtime polymorphism.
With a virtual helper in QObjectPrivate, class authors can add an
override.
Change-Id: I382126ae5a56391d0c7e5ccb58fbbafa6aab5c77
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
-rw-r--r-- | src/corelib/kernel/qobject.cpp | 16 | ||||
-rw-r--r-- | src/corelib/kernel/qobject_p.h | 4 |
2 files changed, 16 insertions, 4 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index d57e13c018..a7dd23048a 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -4472,15 +4472,23 @@ void QObject::dumpObjectInfo() const #ifndef QT_NO_DEBUG_STREAM +void QObjectPrivate::writeToDebugStream(QDebug &dbg) const +{ + Q_Q(const QObject); + dbg.nospace() << q->metaObject()->className() << '(' << (const void *)q; + if (!q->objectName().isEmpty()) + dbg << ", name = " << q->objectName(); + dbg << ')'; +} + QDebug operator<<(QDebug dbg, const QObject *o) { QDebugStateSaver saver(dbg); if (!o) return dbg << "QObject(0x0)"; - dbg.nospace() << o->metaObject()->className() << '(' << (const void *)o; - if (!o->objectName().isEmpty()) - dbg << ", name = " << o->objectName(); - dbg << ')'; + + const QObjectPrivate *d = QObjectPrivate::get(o); + d->writeToDebugStream(dbg); return dbg; } #endif diff --git a/src/corelib/kernel/qobject_p.h b/src/corelib/kernel/qobject_p.h index f42b523c67..68ca9f53a2 100644 --- a/src/corelib/kernel/qobject_p.h +++ b/src/corelib/kernel/qobject_p.h @@ -188,6 +188,10 @@ public: virtual std::string flagsForDumping() const; +#ifndef QT_NO_DEBUG_STREAM + virtual void writeToDebugStream(QDebug &) const; +#endif + QtPrivate::QPropertyAdaptorSlotObject * getPropertyAdaptorSlotObject(const QMetaProperty &property); |