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

Qt createComponent dynamic object bug

    XMLWordPrintable

Details

    Description

      This seems to be an issue with creating a qml object dynamically in javascript.
      Basically, using a QML object as an argument in component.createComponent( parent,

      { arg: object }

      ) for a property which has a default set, fails.

      To display this issue, the test code includes a qml object, ItemParent.qml, which has a property of type ItemProperty that is set to a default itemProperty.
      The property item has a bool property within it (testProperty) defaulted to false.

      In the failing case, a property item is created dynamically using Qt.createObject with it's testProperty set to true.
      var component = Qt.createComponent( "ItemProperty" );
      var myProperty = component.createObject( null,

      { testProperty: true }

      );

      -> qml: myProperty.testProperty: true

      Then an ItemParent is created dynamically using Qt.createObject with the existing ItemProperty (with its true value) as an argument.
      var parentComponent = Qt.createComponent( "ItemParent.qml" );
      var myParent = parentComponent.createObject( null,

      { itemProperty: myProperty }

      );

      The property assignment fails in the first case. Instead the default version of itemProperty is created and set in the ItemParent, and the argument passed into the component.createObject is ignored.

      -> qml: myParent: myParent.itemProperty.testProperty: false

      However, if I repeat the sequence with a derived object of ItemProperty (ItemPropertyDerived), the assignment is successful.
      var component = Qt.createComponent( "ItemPropertyDerived" );
      var myProperty = component.createObject( null,

      { testProperty: true }

      );

      -> qml: myProperty: myProperty.testProperty: true

      Then an ItemParent is created dynamically using Qt.createObject with the existing ItemProperty (with its true value) as an argument.
      var parentComponent = Qt.createComponent( "ItemParent.qml" );
      var myParent = parentComponent.createObject( null,

      { itemProperty: myProperty }

      );
      The property assignment is successful
      -> qml: myParent: myParent.itemProperty.testProperty: true

      Full Output:
      qml: -------------------------------------
      qml: ItemProperty onCompleted: ItemProperty_QMLTYPE_149(0xd8848d0) testProperty: true
      qml: myProperty: ItemProperty_QMLTYPE_149(0xd8848d0) myProperty.testProperty: true
      qml: ItemParent onCompleted: ItemParent_QMLTYPE_151(0x1503a3d8) itemProperty: ItemProperty_QMLTYPE_150(0x1503a3a8) itemProperty.testProperty: false
      qml: ItemProperty onCompleted: ItemProperty_QMLTYPE_150(0x1503a3a8) testProperty: false
      qml: myParent: ItemParent_QMLTYPE_151(0x1503a3d8) myParent.itemProperty: ItemProperty_QMLTYPE_150(0x1503a3a8) myParent.itemProperty.testProperty: false
      qml: -------------------------------------

      qml: -------------------------------------
      qml: ItemProperty onCompleted: ItemPropertyDerived_QMLTYPE_152(0x1503a7e0) testProperty: true
      qml: ItemPropertyDerived onCompleted: ItemPropertyDerived_QMLTYPE_152(0x1503a7e0) testProperty: true
      qml: myProperty: ItemPropertyDerived_QMLTYPE_152(0x1503a7e0) myProperty.testProperty: true
      qml: ItemParent: onItemPropertyChanged: ItemParent_QMLTYPE_151(0x1503ad38) itemProperty: ItemPropertyDerived_QMLTYPE_152(0x1503a7e0) itemProperty.testProperty: true
      qml: ItemParent onCompleted: ItemParent_QMLTYPE_151(0x1503ad38) itemProperty: ItemPropertyDerived_QMLTYPE_152(0x1503a7e0) itemProperty.testProperty: true
      qml: myParent: ItemParent_QMLTYPE_151(0x1503ad38) myParent.itemProperty: ItemPropertyDerived_QMLTYPE_152(0x1503a7e0) myParent.itemProperty.testProperty: true
      qml: -------------------------------------

      Attachments

        1. ItemParent.qml
          0.5 kB
        2. ItemProperty.qml
          0.2 kB
        3. ItemPropertyDerived.qml
          0.3 kB
        4. main.qml
          1 kB
        5. output_dev_6.6.txt
          3 kB

        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
              obinna.modum@garmin.com Obinna Modum
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes