From eb4f183127cb5c73fe84adc296fbc03fa8d61523 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Sat, 10 Dec 2011 10:58:09 +0100 Subject: Add a qDebug operator overload to handle registered enum So if you stream enum type into qDebug, it will show the name of the enum value instead of the int Change-Id: Iec5e826623353560319890d3e7c4ab97d0645f4a Reviewed-by: Marc Mutz Reviewed-by: Shawn Rutledge --- src/corelib/kernel/qobject.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/corelib/kernel/qobject.cpp') diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index be6441933f..0a8369acbf 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -4105,6 +4105,20 @@ QDebug operator<<(QDebug dbg, const QObject *o) dbg << ')'; return dbg; } + +QDebug qt_QMetaEnum_debugOperator(QDebug &dbg, int value, const QMetaObject *meta, const char *name) +{ + QDebugStateSaver saver(dbg); + QMetaEnum me = meta->enumerator(meta->indexOfEnumerator(name)); + const char *key = me.valueToKey(value); + dbg.nospace() << meta->className() << "::" << name << '('; + if (key) + dbg << key; + else + dbg << value; + dbg << ')'; + return dbg; +} #endif /*! -- cgit v1.2.3