Results 1 to 12 of 12

Thread: DeleteLater works... but why?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2007
    Posts
    90
    Thanks
    40
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DeleteLater works... but why?

    Would I get the same same result if the instance of A&C were inside of B?

    IE

    A&C -> signals -> B

    B -> signals -> D (the object that created B) to delete it.

    but A and C are new instances of those classes created in B.

    kind of like:

    Qt Code:
    1. class A : public QObject{
    2. //...
    3. signals:
    4. void sigA(QObject *);};
    5. class B : public QObject{
    6. //...
    7. B() { a= new A(); b=new B(); connect(AtoB); connect(CtoB);}
    8. signals:
    9. void sigB(int);
    10. public slots:
    11. void slotB(QObject *o){ emit sigB(m_list.indexOf(o)); }
    12. };
    13. class C : public QObject {
    14. //...
    15. public slots:
    16. void slotC(QObject *o){...}
    17. };
    18. class D : public QObject {
    19. //...
    20. public:
    21. D() { b = new B(); connect(B to D);}
    22. public slots:
    23. DSlot() { delete b or deletelater b}
    24. };
    To copy to clipboard, switch view to plain text mode 

    and B initiates a call to the D Slot which deletes it and its children.

  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: DeleteLater works... but why?

    The relationship doesn't matter. The only thing that matters is that more than one slot operates on the same object that gets deleted in one of the slots. If that is the case, you have to use deleteLater() or somehow check if the pointer is stil valid (checking for null won't do).

  3. The following user says thank you to wysota for this useful post:

    TheGrimace (6th June 2007)

  4. #3
    Join Date
    May 2007
    Posts
    90
    Thanks
    40
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: DeleteLater works... but why?

    That is most likely what was going wrong then.

    Thank You for your help.

Similar Threads

  1. How signal-slot works across DLL and application???
    By Shuchi Agrawal in forum Newbie
    Replies: 4
    Last Post: 15th May 2007, 11:24
  2. Replies: 3
    Last Post: 28th January 2007, 17:24
  3. How setEnabled() works on QFrames.
    By Doug Broadwell in forum Newbie
    Replies: 4
    Last Post: 18th October 2006, 19:55
  4. Replies: 3
    Last Post: 1st October 2006, 15:03
  5. How simpletreeview example works?
    By igorko in forum Qt Programming
    Replies: 1
    Last Post: 19th June 2006, 09:59

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.