Quote Originally Posted by wysota View Post

Qt Code:
  1. class Object {
  2. public:
  3. Object() { d = new ObjectPrivate; }
  4. Object(const Object &other) : d(other.d){ }
  5. int x() const { return d->x; }
  6. void setX(int x) { d->x = x; }
  7. Object childAt(int i) const { return d->children.at(i); }
  8. void addChild(Object o) { d->children.append(o); o.d->parent = *this; }
  9. Object& operator=(const Object &other) { d = other.d; return *this;}
  10. private:
  11. QSharedPointer<ObjectPrivate> d;
  12. };
  13.  
  14. class ObjectPrivate {
  15. public:
  16. int x;
  17. Object parent;
  18. QList<Object> children;
  19. };
To copy to clipboard, switch view to plain text mode 
It's very interesting realization - it's pimpl

But I see BUG in this code ) - it seems recursive parent destruction - you must use QWeakPointer for parent.