Results 1 to 12 of 12

Thread: when will be QSharedFromThis for QSharedPointer?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2012
    Posts
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: when will be QSharedFromThis for QSharedPointer?

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: when will be QSharedFromThis for QSharedPointer?

    Quote Originally Posted by fsmoke View Post
    It's very interesting realization - it's pimpl
    Yes, it's a kind of pimpl (not completely because there is no "implementation" in the private component, just data). I call this construction a "pointer without pointers".

    But I see BUG in this code ) - it seems recursive parent destruction - you must use QWeakPointer for parent.
    Could be, I didn't test the code before posting.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QSharedPointer with signals and slots
    By xtal256 in forum Qt Programming
    Replies: 20
    Last Post: 7th July 2012, 04:34
  2. QSharedPointer / QWeakPointer in QML?
    By centipede in forum Qt Quick
    Replies: 1
    Last Post: 23rd May 2012, 09:25
  3. emitting QSharedPointer
    By babu198649 in forum Newbie
    Replies: 11
    Last Post: 26th July 2010, 08:51
  4. Problem with QSharedPointer
    By weaver4 in forum Newbie
    Replies: 2
    Last Post: 19th April 2010, 14:22
  5. QSharedPointer vs Boost::tr1::shared_ptr()
    By photo_tom in forum Qt Programming
    Replies: 1
    Last Post: 11th March 2010, 16:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.