[Development] Undeprecating QPointer

Marc Mutz marc.mutz at kdab.com
Fri Mar 2 16:05:02 CET 2012


On Friday March 2 2012, Thiago Macieira wrote:
> Hello
>
> QPointer was ported to a QWeakPointer backend and deprecated early in Qt 5
> history. However, QPointer is used throughout our code and, I can expect,
> in user code too. Replacing it with QWeakPointer is just monkey work,
> adding .data() everywhere and buying us no better safety (because no one
> will bother to verify that the pointer could be got at that point). After
> the port to QWeakPointer, QPointer is no longer slow either.
>
> I'd like to suggest we un-deprecate it and bring it back to full status. At
> the same time, I'd like to suggest we discourage using QWeakPointer for
> tracking QObjects, instead leaving it to its original purpose of being the
> weak reference counterpart to QSharedPointer.
>
> I'm not going as far as suggesting we deprecate the QWeakPointer(QObject*)
> constructor yet. I need to do a bit of research on how a future
> QSharedPointer & QWeakPointer with full "enable_shared_from_this" and
> QObject tracking would look like.

+10

Overloading QWeakPointer with QPointer semantics was a serious mistake for all 
the reasons you mention.

Thanks,
Marc

-- 
Marc Mutz <marc.mutz at kdab.com> | Senior Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
www.kdab.com || Germany +49-30-521325470 || Sweden (HQ) +46-563-540090
KDAB - Qt Experts - Platform-Independent Software Solutions



More information about the Development mailing list