Results 1 to 12 of 12

Thread: To use or not to use: deleteLater()

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2009
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: To use or not to use: deleteLater()

    Quote Originally Posted by MrDeath View Post
    deleteLater() can delete your object at any time. You ask qt that you do not need the object and qt can delete it anytime(may be instantly)..
    Hmm, I thought that deleteLater() always deletes object on next event loop iteration, so it never happens "instantly" after being issued. Or am I wrong?

  2. #2
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: To use or not to use: deleteLater()

    Quote Originally Posted by dpimka View Post
    Hmm, I thought that deleteLater() always deletes object on next event loop iteration, so it never happens "instantly" after being issued. Or am I wrong?
    deleteLater() can delete your object at any time when the event loop has control, sometimes that can be instantly if there aren't any other events.

  3. #3
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: To use or not to use: deleteLater()

    Quote Originally Posted by codeslicer View Post
    deleteLater() can delete your object at any time when the event loop has control, sometimes that can be instantly if there aren't any other events.
    looks like you learn very fast

    So does that mean it's better to make "new" objects because those can be deleted? Or only reserve smaller objects (like bool and int) for the stack?
    this is a tricky question.
    in qt any class which is derived from qobject can have children(fox example a QDialog containg Ok,Cancel button as its children). Now when the qdialog is deleted, it also deletes all its children,,, if the children are on stack that will cause crash. So all the QObjects derived classes which will become child of any object in your program should be on heap.

    but this is not general rule. many times a local child widget is created on stack(for example a temporary messagebox)

  4. The following user says thank you to nish for this useful post:

    codeslicer (10th July 2009)

Similar Threads

  1. Replies: 4
    Last Post: 19th February 2009, 11:10
  2. QT deleteLater again.
    By bunjee in forum Qt Programming
    Replies: 1
    Last Post: 10th May 2008, 22:36
  3. Qt Deletelater
    By bunjee in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2008, 16:58
  4. DeleteLater works... but why?
    By TheGrimace in forum Qt Programming
    Replies: 11
    Last Post: 6th June 2007, 15:14

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.