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

Ancestor's activeFocus bound to a grouped property gives strange errors upon destruction

    XMLWordPrintable

Details

    Description

      Run the following test app. It throws TypeError: Cannot read property of null. If the app is run with QML debugging enabled, you get TypeError: Cannot read property 'activeFocus' of null instead. Interestingly, if you use 'parent' instead of 'myItem' in the binding, you get ReferenceError: parent is not defined instead.

      There is something fishy going on - it only happens when 'activeFocus' of an ancestor is bound to a grouped property. 'activeFocus' is a special property that is recursively cleared in children during the destruction. When the error occurs, the grand parent has just started its destruction and is clearing its parent & focus, but the target item in the binding is fully alive and its QML context seems valid too, so I'm not sure why it fails to evaluate the expression like that.

      import QtQuick 2.6
      import QtQuick.Window 2.2
      
      Window {
          id: window
          width: 360
          height: 360
          visible: true
      
          Component {
              id: emptyItem
              Item { }
          }
      
          Component {
              id: testItem
              Item {
                  id: myItem
                  Item {
                      layer.enabled: myItem.activeFocus // <== any grouped property bound to ancestor's activeFocus
                  }
              }
          }
      
          Component.onCompleted: {
              // 2 levels of parents, intentionally, to make sure that the potential fix
              // does not rely on something in the immediate parent. the problematic focus
              // clearing can originate from one of the grand parents. in this example, the
              // warning is thrown during the destruction of _grandparent_.
      
              var grandparent = emptyItem.createObject(window.contentItem, {objectName: "grandparent"})
              var parent = emptyItem.createObject(grandparent, {objectName: "parent"})
              var child = testItem.createObject(parent, {objectName: "child"})
              child.forceActiveFocus()
              grandparent.destroy(0)
          }
      }
      

      This results from QTBUG-57650 - strange warnings in Qt Quick Controls 2 auto tests.

      Attachments

        Issue Links

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

          Activity

            People

              srutledg Shawn Rutledge
              jpnurmi J-P Nurmi
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes