Details
-
Bug
-
Resolution: Fixed
-
P4: Low
-
5.15, 6.5.0
-
None
-
-
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
- is cloned by
-
QTBUG-113282 Don't detach QVariant in setProperty()/QMP::write()
-
- Reported
-
-
QTBUG-113281 QObject::setProperty() detaches value argument
-
- Closed
-
For Gerrit Dashboard: QTBUG-112762 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
472018,4 | Avoid a QVariant detach in QMetaProperty::write (quick fix) | dev | qt/qtbase | Status: NEW | -1 | 0 |
472039,5 | QMetaProperty::write: avoid copying the input value | dev | qt/qtbase | Status: NEW | -1 | 0 |
472388,1 | moc: enforce that property setters should take by value or const-ref | dev | qt/qtbase | Status: NEW | -1 | 0 |