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

[REG 6.2 → 6.5] Qt.binding fails with QtQObject inside createObject

    XMLWordPrintable

Details

    • Linux/Wayland
    • 8bfd582da (dev), eb460e4ee (6.8), ef97a93f3 (6.7), 8b1467db9 (tqtc/lts-6.5)

    Description

      Qt.binding fails with QtQObject inside createObject with output 'Could not set initial property obj'

      consider the following script

      import QtQuick
      
      Item {
      
      	property Component object: QtObject {
      		property QtObject obj
      	}
      	
      	Component.onCompleted: {
      		const item = object.createObject(this, { obj: null })
      		const item2 = object.createObject(this, { obj: Qt.binding(() => item) })
      		print(item, item.obj, item2, item2.obj)
      	}
      }
      

      Output -

      prince@prince-virtual-machine:~/Desktop/tests 
      $ /home/prince/Qt/6.2.4/gcc_64/bin/qml binding.qml 
      qml: QObject_QML_1(0x1905f40) null QObject_QML_1(0x1911ad0) QObject_QML_1(0x1905f40)
      
      prince@prince-virtual-machine:~/Desktop/tests 
      $ /home/prince/Qt/6.6.3/gcc_64/bin/qml binding.qml 
      file:///home/prince/Desktop/tests/binding.qml: Could not set initial property obj
      qml: QObject_QML_1(0x57d68badfd90) null QObject_QML_1(0x57d68bae2c30) null
      
      

      As you can see above Qt 6.6.3 fails while Qt6.2.4 gives the correct output, Same behaviour can be observed with a Q_GADGET

      Edit: Note that changing obj property type to 'var', fixes the problem

      Attachments

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

        Activity

          People

            ulherman Ulf Hermann
            jagannatharjun Prince Gupta
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes