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

calling forceActiveFocus from onFocusChanged handler causes dangling pointer and crash (with patch)

    XMLWordPrintable

Details

    • ee60e9c88c43cc33dc94a4cec79c62ffdf02ce58

    Description

      While using the Qt Components for Desktop I've run into a crash that happened when using the TextField component inside a delegate. The cause for the crash lies within the implementation of TextField:

      onFocusChanged: {
              if (textField.activeFocus) {
                  textInput.forceActiveFocus();
              }
          }
      

      This handler is called from QGraphicsItemPrivate::setParentItemHelper after "ensuring any last parent focus scope does not point to this item or any of its descendents".

      The problems start when the focus is modified from inside the handler. In this case the clearing is reverted and the focusScopeItem pointer again points to the item that will no longer be a descendant of the old parent.

      Now when that item is being deleted, it will no longer clear itself from that old parent, so we have a dangling pointer there that will cause a crash sooner or later (whenever the focus scope item list is being iterated through).

      The proposed fix is attached as a patch.

      Attachments

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

        Activity

          People

            dajansen Damian Jansen (closed Nokia identity) (Inactive)
            njeisecke Nils Jeisecke
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes