[Development] The future of smart pointers in Qt API
Vitaly Fanaskov
vitaly.fanaskov at qt.io
Fri Jan 31 15:46:27 CET 2020
> 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.
I'm not sure how to properly identify what is the "complicated
ownership". I don't think that there are places in Qt API where we
really need something more complicated than regular shared/weak/unique
pointers. Even intrusive pointers are not required I guess. When you
think about something more complicated, this is probably an
architectural problem (like with parent-child) or bad API design.
Can you provide some real examples where we need something more
complicated than regular smart pointers, please?
On 1/31/20 3:30 PM, Allan Sandfeld Jensen wrote:
> 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/
> c/qt/qtbase/+/284769
>
> The ownership is simple, and the std api supplementing the existing one,
> without needed ABI or API changes.
>
> best regards
> 'Allan
>
>
--
Best Regards,
Fanaskov Vitaly
Senior Software Engineer
The Qt Company / Qt Quick and Widgets Team
More information about the Development
mailing list