Details
-
Bug
-
Resolution: Fixed
-
P4: Low
-
5.15, 6.5.0
-
None
-
-
2
-
39cdf431f (dev)
-
Foundation Sprint 81, Foundation Sprint 82, Foundation Sprint 83
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
- clones
-
QTBUG-112762 QMetaProperty::write detaches value argument
- Closed