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

Component::createObject fails to assign initial list property

XMLWordPrintable

      In the following minimal reproducible example Component::createObject is called on a component of some type that has a list property, and that list property is initialized with an empty JavaScript array value. The fact that it is empty is not important, because component would attempt to interpret array value as a whole as a QtObject, causing it to be casted as null.

      In fact, passing some actual QObject without array brackets results in a list property having that one single object in it.

      import QtQml
      
      QtObject {
          objectName: "root"
          property Component testComponent: QtObject {
              property list<QtObject> bug
          }
          Component.onCompleted: {
              let obj = testComponent.createObject(this, {
                  bug: [],
              });
              print(obj, obj.bug.length, obj.bug);
              // Prints: QObject_QML_1 1 [null]
      
              obj = testComponent.createObject(this, {
                  bug: this,
              });
              print(obj, obj.bug.length, obj.bug);
              // Prints: QObject_QML_1 1 [QObject_QML_0("root")]
          }
      }
      

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

            ulherman Ulf Hermann
            ratijas ivan tkachenko
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes