Sign up for the KDAB Newsletter
Stay on top of the latest news, publications, events and more.
Go to Sign-up
Find what you need - explore our website and developer resources
3 May 2023
How is "const Data*" different from "Data * const"?
If you have an instance variable "Data* m_data" in a class, can you then change the data pointed to in a const method? (The answer is a bit unexpected, yes).
In this episode, Jesper interviews Peppe on a helper class called propogate_const, which also makes the pointed-to object const in const methods.
Links mentioned in this video:
* Blog post on "QObjects, Ownership, propagate_const and C++ Evolution": https://www.kdab.com/qobject_ownership_propagate_const/
* Episode on "Working with Git Sub-Modules": https://www.youtube.com/watch?v=Np8FOQ4nM4U
00:00 intro
00:40 What is const useful for?
02:50 Why do we use pointers in Qt?
12:10 Constness and pointers
20:00 Const methods 101
22:15 What happens with pointer data members in const methods?
26:08 Introducing propagate_const
33:30 How to deal with autogenerated code
37:20 Can we automatically refactor existing code?
All QML tips and tricks videos : https://www.youtube.com/playlist?list=PL6CJYn40gN6jWHP5krsQrVGyYtKh3A3be
All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI