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

DynamicRoleModel is unsafe

XMLWordPrintable

      The DynamicRoleModel code performs unsafe qobject_cast operations in its dtor and in the propertyWrite function.

      The code assumes that if the data at that index is a QObject pointer, that the QObject is still valid / hasn't been destroyed, but the model doesn't necessarily have ownership of that object (unless it was a sub-model which it created in propertyWritten) and since the QObject pointer is stored in a QVariant, it's not guarded in any way.

      Some possible solutions:
      1) store a QSet of sub-model indices, which is maintained in propertyWritten, and only access/delete the QObject pointers at those indices in the dtor / propertyWrite.
      2) guard ALL qobject pointers by having a QHash of QObject pointer to data index + role, and connecting the qobject::destroyed() signal to a guard function which updates the data at the related index/role to null.

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

            shausman Simon Hausmann
            chrisadams Christopher Adams
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes