Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
5.13.0 RC 3
Description
Problem
Given this property in the declaration of the class Foo:
Q_PROPERTY(QQmlListProperty<Bar> bars READ bars)
And this QML code:
Foo { bars: [ Bar{}, Bar{} ] }
I get the error:
Invalid property assignment: "bars" is a read-only property
However this is incorrect. The Q_PROPERTY only has a READ qualifier, but that is how QQmlListProperty is supposed to work (see https://doc.qt.io/qt-5/qqmllistproperty.html). Also looking at the example at https://doc.qt.io/qt-5/qtqml-referenceexamples-properties-example.html there isn't any indication of what went wrong.
I eventually found the solution to use a fully qualified namespace on the forums, at https://forum.qt.io/topic/45581/read-only-property-error-when-using-qqmllistproperty-with-custom-class-in-qml/9 .
Solution proposal
1) Add a big fat warning to the docs about having to use fully qualified namespaces (accompanied by the error message above, so it can be found using your favorite search engine), or
2) Let the Q_PROPERTY system support QQmlListProperty without fully qualified namespaces.
Extra
I believe this is also the case with enum classes used as Q_PROPERTY's.
Attachments
Issue Links
- is duplicated by
-
QTBUG-83028 default property of QQmlListProperty of class in a namespace doesn't work
- Closed