[Development] Making QScopedPointer scoped (again)

Thiago Macieira thiago.macieira at intel.com
Wed Sep 4 17:54:11 CEST 2013


On quarta-feira, 4 de setembro de 2013 10:20:39, Peter Kümmel wrote:
> > 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.

You're confusing QScopedPointer's purpose. Despite its name, it's not just 
about scope. It's about simplifying the handling of the pointer's deletion 
when an exception is thrown.

Taking the pointer out via take() and storing it in a raw pointer defeats that 
purpose.

	q.reset(p.take()); is exception-safe
	return p.take();  isn't

if we want to return exception-safely, we need this.

Note: we don't care anymore about exceptions.
-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/development/attachments/20130904/4d43567d/attachment.sig>


More information about the Development mailing list