When running the attached project, I get the following output:
As described here, the solution is to use Q_DECLARE_METATYPE:
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:
- 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.
- 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.