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

QObject::setProperty() detaches value argument

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4: Low P4: Low
    • 6.6.0 FF
    • 5.15, 6.5.0
    • Core: Object Model
    • None
    • All
    • 2
    • 39cdf431f (dev)
    • Foundation Sprint 81, Foundation Sprint 82, Foundation Sprint 83

      QMetaProperty::write (and by extension, QObject::setProperty) perform a detach of the passed in QVariant value. The argument to QMetaProperty::write is a const QVariant&, and the documentation gives no warnings of anything funny going on.  The setter of the property we're trying to write takes a const CustomType& so there is no reason to suspect a detach of the QVariant is going to happen. 

      But, in QMetaProperty::write, first a copy of the value is taken. This is still shallow. But a little bit later, where the value is stuffed into a Q_ARG in order to call the setter via QMetaCall, QVariant::data is called on the non-const copy of the value. And as ::data isn't const, we get a detach and thus a deep copy of the value there.

      As a user, I did not expect this API to cause a detach. There is no warning about it in the documentation, and it takes a const QVariant&, and the setter is also using const ref. Perhaps constData() could be used instead of data()? 

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

            mmutz Marc Mutz
            mmutz Marc Mutz
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes