Description
Assume the user needs to register e.g., QMap<int, int> as a meta type to be used with QDBus. With the normal and documented Q_DECLARE_METATYPE + qRegisterMetaType + qDBusRegisterMetaType setting, this is not possible, since the comma in QMap<int, int> confuses the Q_DECLARE_METATYPE macro.
A fragile workaround is:
typedef QMap<int, int> MyType;
Q_DECLARE_METATYPE(MyType)
qRegisterMetaType<MyType>();
qDBusRegisterMetaType<MyType>();
However, this creates problems when a library and an application using the library register the same type under different names.
In more detail:
The library does this:
typedef QMap<int, int> MyType;
Q_DECLARE_METATYPE(MyType)
qRegisterMetaType<MyType>();
qDBusRegisterMetaType<MyType>();
The application using it does this:
typedef QMap<int, int> MyOtherType;
Q_DECLARE_METATYPE(MyOtherType)
qRegisterMetaType<MyOtherType>();
Now the D-Bus marshaller and demarshaller get registered with the wrong type id. As a result, if the library connects a D-Bus signal to a slot with a signature "void mySlot(MyType)", it is not called when the D-Bus signal arrives. (See the attachment for a full example program; a D-Bus server sending a signal of this signature is also included. If you comment away the qRegisterMetaType<MyOtherType>(); line in the application, the signal arrives correctly.)
Library writers have no control over what typedefs the applications use, and the applications have no control over what typedefs the libraries use. Thus, using typedef with QDBus metatype registration is not a solution to the original comma problem.