Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
dev
-
None
Description
The following code cases the call of int a() but not the int a() const as could expected.
class MyClass { Q_OBJECT Q_PROPERTY(int a READ a) int a() const { qDebug() << "const"; return m_a; } int &a() { qDebug() << "non-const"; return m_a; } private: int m_a = 1; };
This happens because the reader code accesses the MyClass uses pointer to non-const data when reading values:
if (_c == QMetaObject::ReadProperty) { auto *_t = reinterpret_cast<MyClass *>(_o); (void)_t; void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< int*>(_v) = _t->a(); break; default: break; }
It would be nice to detect this situation and force calling const function instead, since mutable getters might lead to really expensive shared data detach.
Attachments
Issue Links
- is required for
-
QTBUG-119913 When accessing protobuf message properties, propety values always detaches the internal shared data
- Closed
Gerrit Reviews
For Gerrit Dashboard: QTBUG-119912 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
598155,5 | WIP: moc: Prefer const getter whenever possible | dev | qt/qtbase | Status: NEW | -2 | -1 |