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

QMetaProperty::write detaches value argument

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4: Low
    • 6.6.0
    • 5.15, 6.5.0
    • Core: Object Model
    • None
    • All
    • 2
    • 968250ee1 (dev), 426b5fbce (dev), b6d04c8a8 (dev), f961f5e22 (dev), dc69102f4 (dev), f6d54db96 (dev), ceb00a84d (6.5), 39cdf431f (dev)
    • Foundation Sprint 81

    Description

      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()? 

      Attachments

        Issue Links

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

          Activity

            People

              mmutz Marc Mutz
              andre André Somers
              Vladimir Minenko Vladimir Minenko
              Alex Blasche Alex Blasche
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: