[Development] Making QScopedPointer scoped (again)

Peter Kümmel syntheticpp at gmx.net
Wed Sep 4 10:20:39 CEST 2013


On 04.09.2013 09:16, Thiago Macieira wrote:
> On quarta-feira, 4 de setembro de 2013 09:00:14, Peter Kümmel wrote:
>> But then you could use take() add wrap the pointer with something else,
>> only this way I would call "explicit".
>
> What's that something else? Remember that QScopedPointer was created to
> simplify handling of exceptions (when we tried to care about exceptions). If
> we have to take the pointer out and handle it manually, it defeats the entire
> purpose of QScopedPointer -- simplifying exception management.

This "something else" we have to introduce in Qt (it would be very similar to
QScopedPointer), because initially QScopedPointer wasn't made for it,
and all "escaping from scope" questions if QScopedPointer is the right
choice at this place.

And in RAII you should make it as hard as possible to let the resource "escape"
because this escaping breaks the pattern.

>
> To ensure proper RAII, we need to have a hand-off to another object. What class
> is that other object that allows returning or passing?
>
>> Do we really wanna pollute Qt's API with QScopedPointer-s?
>
> No, I don't. I'm just presenting arguments.

But when it is possible, I assume people wanna use it.

Peter



More information about the Development mailing list