changeset 1759:b679bae1627b by-id

Print object name as well (if a QObject)
author Chris Cannam
date Mon, 08 Jul 2019 10:07:55 +0100
parents 83178b4bb698
children 9945ad04c174
files base/ById.cpp
diffstat 1 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/base/ById.cpp	Sun Jul 07 16:42:47 2019 +0100
+++ b/base/ById.cpp	Mon Jul 08 10:07:55 2019 +0100
@@ -50,10 +50,16 @@
             SVCERR << "WARNING: ById map is not empty at close; some items have not been released" << endl;
             SVCERR << "         Unreleased items are:" << endl;
             for (const auto &p: m_items) {
-                if (p.second && p.second.use_count() > 0) {
-                    SVCERR << "         - id #" << p.first
-                           << ": type " << typeid(*p.second.get()).name()
-                           << ", use count " << p.second.use_count() << endl;
+                auto ptr = p.second;
+                if (ptr && ptr.use_count() > 0) {
+                    QString message = QString("id #%1: type %2")
+                        .arg(p.first).arg(typeid(*ptr.get()).name());
+                    if (auto qobj = std::dynamic_pointer_cast<QObject>(ptr)) {
+                        message += QString(", object name \"%1\"")
+                            .arg(qobj->objectName());
+                    }
+                    message += QString(", use count %1").arg(ptr.use_count());
+                    SVCERR << "         - " << message << endl; 
                 }
             }
         }