Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-11485

No safe way for registering D-Bus metatypes with commas

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 4.7.0
    • 4.6.2, 4.7.0
    • D-Bus
    • None
    • Ubuntu; Maemo

    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.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            goffart Olivier Goffart (closed Nokia identity) (Inactive)
            marja Marja Hassinen
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes