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

Problem with accessing revisioned properties from QML

    XMLWordPrintable

Details

    Description

      If revisioned property of a class is set via another property, the import version information is somehow ignored.

      For example, I have these two properties in my abstract base class:

      class MyAbstractBaseClass : public QObject
      {
          Q_OBJECT
          // "originalProp" was in the initially released version
          Q_PROPERTY(bool originalProp READ originalProp WRITE setOriginalProp NOTIFY originalPropChanged)
      
          // "newProp" was introduced in version 1.1, and therefore has revision 1
          Q_PROPERTY(bool newProp READ newProp WRITE setNewProp NOTIFY newPropChanged REVISION 1)
          //...
      

      I register revisions like this:

          qmlRegisterUncreatableType<MyAbstractBaseClass>("MyTypes", 1, 0, "MyAbstractBaseClass",
                                                          QLatin1String("Trying to create uncreatable: MyAbstractBaseClass."));
      
          qmlRegisterUncreatableType<MyAbstractBaseClass, 1>("MyTypes", 1, 1, "MyAbstractBaseClass",
                                                             QLatin1String("Trying to create uncreatable: MyAbstractBaseClass."));
      

      The abstract class is subclassed by "MySubClass", which is then used as a property in another class:

      class MyItem : public QObject
      {
          Q_OBJECT
          Q_PROPERTY(MySubClass* first READ first WRITE setFirst NOTIFY firstChanged)
          Q_PROPERTY(MySubClass* second READ second WRITE setSecond NOTIFY secondChanged)
          //...
      

      Now, in QML, I try to set the properties as follows, but trying to set the "newProp" in the context of the MyItem fails:

      Window {
          visible: true
          width: 360
          height: 360
      
          MySubClass {
              id: mySubClass
              originalProp: false
              // If MySubClass item is declared like this, it can use revision 1 property just fine
              newProp: false
          }
      
          MyItem {
              id: myItem
      
              // This works as expected
              first: mySubClass
      
              // Using the original revision 0 property from default object like this works just fine:
              second.originalProp: false
      
              // Using the revision 1 property from default object like this gives an error:
              // --> qrc:///main.qml:28 ".newProp" is not available due to component versioning.
              second.newProp: false
          }
          //...
      

      As the code comments above describe, trying to do "second.newProp: false" complains about "newProp" not being available due to component versioning, even though it was successfully used in MySubClass scope above.

      Also, doing this later in onClicked scope works fine, so the above error definitely feels like a bug:

          console.log("myItem.second.newProp: ", myItem.second.newProp)
      

      Attached an example application to demonstrate the issue.

      Am I registering the QML types somehow incorrectly, or is there a bug in Qt?

      Attachments

        Issue Links

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

          Activity

            People

              shausman Simon Hausmann
              e0348803 Miikka Heikkinen
              Votes:
              4 Vote for this issue
              Watchers:
              16 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes