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

No indication of the root cause or solution when enum parameter of signal is not recognised

    XMLWordPrintable

Details

    Description

      When running the attached project, I get the following output:

      qml: damaging
      qml: ondamaged
      qml: ConditionSystem(0xa290aff5f0)
      qml: undefined undefined undefined undefined
      

      As described here, the solution is to use Q_DECLARE_METATYPE:

      Q_DECLARE_METATYPE(ConditionComponent::DamageDegree)
      

      However, that took me a while to find, and I only knew about it because I'd had the problem before. There should be a clear error message that tells the user why their arguments are all undefined.

      The only documentation I could find was here:

      C++ signals and methods with enumeration-type parameters can be used from QML provided that the enumeration and the signal or method are both declared within the same class, or that the enumeration value is one of those declared in the Qt Namespace.

      Additionally, if a C++ signal with an enum parameter should be connectable to a QML function using the connect() function, the enum type must be registered using qRegisterMetaType().

      There are two issues with this:

      1. The first paragraph says it's not possible to do what the attached example does; it doesn't mention that the enum can be from another class as long as Q_DECLARE_METATYPE is used.
      2. Assuming that "QML function" also covers functions in Connections objects, it mentions qRegisterMetaType(), whereas the comment linked above says Q_DECLARE_METATYPE.

      If Q_DECLARE_METATYPE is the intended way of doing this, the documentation should be corrected. In any case, the documentation should have code examples to make it clearer.

      Attachments

        1. qtbug87170.zip
          3 kB
          Mitch Curtis

        Issue Links

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

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              mitch_curtis Mitch Curtis
              Votes:
              2 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes