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

QQmlListProperty doesn't work without fully qualified namespace

    XMLWordPrintable

Details

    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

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

          Activity

            People

              qtqmlteam Qt Qml Team User
              jdubb Jan Willem Silfhout
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes