Also register complex D-Bus types when running under qdbus

When running inside qdbus, we generate the meta objects a little
differently. Previously, for unknown types we'd simply have a -1 as the
type ID in the meta object, but this doesn't work in Qt 5 (has
apparently never worked). So simply register a type with the metatype
system and let QMetaObject do its thing.

[ChangeLog][qdbus]Fixed a bug that caused the qdbus tool to crash
when trying to display remote interfaces that had complex types
without a matching base Qt type.

Task-number: QTBUG-36524
Change-Id: Ifef65b340dc89d3295ed6ef00f2dcc60849ecb02
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
bb10
Thiago Macieira 2014-01-29 12:35:43 -08:00 committed by The Qt Project
parent cc8e0d85e2
commit 15f8bc1f6e
1 changed files with 19 additions and 14 deletions

View File

@ -128,12 +128,7 @@ QDBusMetaObjectGenerator::QDBusMetaObjectGenerator(const QString &interfaceName,
}
}
Q_DBUS_EXPORT bool qt_dbus_metaobject_skip_annotations = false;
QDBusMetaObjectGenerator::Type
QDBusMetaObjectGenerator::findType(const QByteArray &signature,
const QDBusIntrospection::Annotations &annotations,
const char *direction, int id)
static int registerComplexDBusType(const char *typeName)
{
struct QDBusRawTypeHandler {
static void destroy(void *)
@ -159,6 +154,22 @@ QDBusMetaObjectGenerator::findType(const QByteArray &signature,
}
};
return QMetaType::registerNormalizedType(typeName, QDBusRawTypeHandler::destroy,
QDBusRawTypeHandler::create,
QDBusRawTypeHandler::destruct,
QDBusRawTypeHandler::construct,
sizeof(void *),
QMetaType::MovableType,
0);
}
Q_DBUS_EXPORT bool qt_dbus_metaobject_skip_annotations = false;
QDBusMetaObjectGenerator::Type
QDBusMetaObjectGenerator::findType(const QByteArray &signature,
const QDBusIntrospection::Annotations &annotations,
const char *direction, int id)
{
Type result;
result.id = QVariant::Invalid;
@ -195,13 +206,7 @@ QDBusMetaObjectGenerator::findType(const QByteArray &signature,
// 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() + ">*";
type = QMetaType::registerType(typeName, QDBusRawTypeHandler::destroy,
QDBusRawTypeHandler::create,
QDBusRawTypeHandler::destruct,
QDBusRawTypeHandler::construct,
sizeof(void *),
QMetaType::MovableType,
0);
type = registerComplexDBusType(typeName);
}
result.name = typeName;
@ -217,7 +222,7 @@ QDBusMetaObjectGenerator::findType(const QByteArray &signature,
type = QVariant::Map;
} else {
result.name = "QDBusRawType::" + signature;
type = -1;
type = registerComplexDBusType(result.name);
}
} else {
result.name = QMetaType::typeName(type);