Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
5.15
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:
- 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.
Attachments
Issue Links
- relates to
-
QTBUG-58454 Q_ENUMs from one class cannot be used as a Q_INVOKABLE function parameter of another class
- Closed