From c4182bd5e791c6e209c5084c33e4f6a105722d5f Mon Sep 17 00:00:00 2001
From: Thiago Macieira <thiago.macieira@intel.com>
Date: Mon, 30 Mar 2026 11:47:58 -0400
Subject: [PATCH] QDBusMetaObject: ensure custom types are normalized

The QMetaTypeInterface::name field has been expected to be normalized
since commit 4dbac23e5354638224d8d99ba3342067c015a04b from 6.0. This
code from 5.2 didn't do that, despite having been updated for 6.0. We
just never noticed because QMetaType was lenient.

That changed in commit cfcf10e0911ec778c1de112fcbbd34cea4612598
("QMetaType: Optimize unregistering of custom types") from 6.11, which
changed the unregistration code to rely on that assumption. That caused
the search for a metatype in unregisterDynamicType() to fail to find
anything and thus crash when dereferencing the end:

        auto it = aliases.find(ti->name);
        if (it->data() == ti) {

[ChangeLog][Tools][qdbus] Fixed a bug that would cause the tool to crash
on exit when querying remote objects containing complex arguments.

Fixes: QTBUG-145359
Pick-to: 6.11
Change-Id: Ia2f22f953e28a100b0d0fffdfae6f2a6d28ac5f8
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
---

diff --git a/src/dbus/qdbusmetaobject.cpp b/src/dbus/qdbusmetaobject.cpp
index 149392f..70b861e 100644
--- a/src/dbus/qdbusmetaobject.cpp
+++ b/src/dbus/qdbusmetaobject.cpp
@@ -173,6 +173,7 @@
             // type is still unknown or doesn't match back to the signature that it
             // was expected to, so synthesize a fake type
             typeName = "QDBusRawType<0x" + signature.toHex() + ">*";
+            Q_ASSERT(typeName == QMetaObject::normalizedType(typeName));
             type = registerComplexDBusType(typeName);
         }
 
@@ -195,6 +196,7 @@
             type = qMetaTypeId<QByteArrayList>();
         } else {
             result.name = "{D-Bus type \"" + signature + "\"}";
+            result.name = QMetaObject::normalizedType(result.name);
             type = registerComplexDBusType(result.name);
         }
     } else {
