[Development] The future of smart pointers in Qt API

Allan Sandfeld Jensen kde at carewolf.com
Fri Jan 31 15:30:12 CET 2020

On Friday, 31 January 2020 11:07:52 CET Vitaly Fanaskov wrote:
> Hello everyone,
> We’ve been discussing for a while how Qt6 API can be improved with using 
> smart pointers. Recently we came into some conclusions and want to 
> discuss them with the community.
> Smart pointers are for sure much better to use than raw pointers for 
> many reasons. They manage lifetime automatically, show ownership 
> semantic, and make code safer. It’s planned to officially recommend them 
> to use in Qt6 API instead of raw pointers whenever this is possible. For 
> sure, it should only be a choice for newly designed API.
> But how to use them in the API and which way is preferable is still 
> unclear. There are two main options we have:
> 1) Use std::*  smart pointers as-is.
> 2) Add Qt-style wrappers around std::* smart pointers and move old 
> implementations of Qt smart pointers to the Qt5Compact module.
I would like to separate pointers with simple ownership and complicated 
ownership. We could solve passing of raw pointers with simple ownership
first using standard smart pointers. Where as the more complicated pointers
would require special classes like those Daniel Teske has been working on.

An example is water testing change I made: https://codereview.qt-project.org/

The ownership is simple, and the std api supplementing the existing one, 
without needed ABI or API changes.

best regards

More information about the Development mailing list