[Development] Unnecessary ambiguity in Qt documentation about reentrancy and safety of const methods.
Giuseppe D'Angelo
giuseppe.dangelo at kdab.com
Sat Jul 18 23:48:34 CEST 2026
On 18/07/2026 19:41, Thiago Macieira wrote:
> If the class is using a smart pointer for the Private, the smart pointer will
> propagate the constness of the public function and it will be easy to notice
> where we violate by way of a const_cast. Older classes often use raw pointers,
> which don't propagate const, and then we may perform non-const operations,
> intentionally or not.
For QMap I introduced QESDPV2 precisely because I wanted deep constness.
Neither QESDP nor the standard library smart pointers propagate, and
those are landmines. We should likely also introduce a private
propagate_const if someone really needs a raw pointer for whatever reason.
This is also documented as THICK.8 in
https://codereview.qt-project.org/c/meta/quips/+/321050
(I also ported uic to generate propagate_const<> around the QWidget*
data members in the ui class, catching many logical constness bugs in
some projects.)
My 2 c,
--
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - Trusted Software Excellence
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4850 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.qt-project.org/pipermail/development/attachments/20260718/6c4f116b/attachment.bin>
More information about the Development
mailing list