[Development] On QML, ownership, QObject-trees and QSharedPointer

Thiago Macieira thiago.macieira at intel.com
Thu May 24 18:43:09 CEST 2012

On quinta-feira, 24 de maio de 2012 16.33.53, Olivier Goffart wrote:
> > I've long wanted to make QSharedPointer on QObject-derivatives participate
> > in the whole-tree ownership, somehow. I introduced QSharedPointer in 4.4
> > and I did some work in 4.5 to make that work.
> > 
> > My original solution was to have a parent only deref its children's shared
> > pointer counter, deleting it only if it became zero. That means that if
> > you
> > had a QSharedPointer to an object in the middle of the hierarchy, that
> > object would be orphaned instead of deleted when the parent died. The
> > converse was that when the last QSharedPointer reference to a QObject went
> > away, the object might survive if it still had a parent.
> So that would be like having "children" be in implemented as a
> QList<QSharedPointer<QObject> > ?

Yes, like that, but not actually implemented with that.

> But I personaly think it shoud not be the case.  QSharedPointer is
> orthogonal with object tree as much as it is orthogonal with
> std::shared_ptr or QScopedPointer or manually delete.
> You have to pick how you do thememory management for a given pointer and
> stick to it.

It is orthogonal and right now it's working orthogonally.

This was just something I experimented with, but didn't work as intended. It 
crashed QWidget left and right.

Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
     Intel Sweden AB - Registration Number: 556189-6027
     Knarrarnäsgatan 15, 164 40 Kista, Stockholm, Sweden
-------------- 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/20120524/68539fd1/attachment.sig>

More information about the Development mailing list