Results 1 to 3 of 3

Thread: Difference between WA_DeleteOnClose = true and deleteLater()

  1. #1
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Difference between WA_DeleteOnClose = true and deleteLater()

    Hello!

    My question: is there a difference between using setAttribute(Qt::WA_DeleteOnClose, true); and deleteLater(); ?

    To give a context: I want to create a modeless dialog, so I may use it and its parent at the same time. But I also don want just to create a pointer to it using show() and no delete ... to avoid unecessary memory comsumption when the dialog is closed and its parent isn't yet closed. So I figured out that, if I put deleteLater() in the closeEvent(QClosEvent*); reimplemented function or if I use the window attribute, setting it in the constructor, either way the object is destroyed when the dialog is closed.

    A second question is, which of them should I use preferentially?


    Thanks,

    Momergil

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Difference between WA_DeleteOnClose = true and deleteLater()

    Qt::WA_DeleteOnClose setting makes a call to the widget deleteLater. If you do not have to override the methods that do not.

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

    Momergil (13th October 2013)

  4. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Difference between WA_DeleteOnClose = true and deleteLater()

    My personal preference would be to use the widget attribute and to set it from the code that creates the dialog, i.e.
    Qt Code:
    1. MyDialog *dialog = new MyDialog(this);
    2. dialog->setAttribute(Qt::WA_DeleteOnClose, true);
    3. dialog->show();
    To copy to clipboard, switch view to plain text mode 

    The main motivation for doing it in such an explicit way is that anyone reading the code of the instatiation immediately sees that the deletion is taken care of.

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    Momergil (13th October 2013)

Similar Threads

  1. WA_DeleteOnClose and exec()
    By Wasabi in forum Newbie
    Replies: 6
    Last Post: 7th August 2011, 05:54
  2. To use or not to use: deleteLater()
    By codeslicer in forum Qt Programming
    Replies: 11
    Last Post: 11th July 2009, 21:43
  3. Qt::WA_DeleteOnClose - object persistance
    By ranna in forum Qt Programming
    Replies: 0
    Last Post: 4th June 2009, 07:08
  4. Qt::WA_DeleteOnClose while a child QDialog is executed
    By nooky59 in forum Qt Programming
    Replies: 4
    Last Post: 11th July 2008, 12:45
  5. Qt::WA_DeleteOnClose
    By merlvingian in forum Newbie
    Replies: 3
    Last Post: 22nd November 2006, 18:38

Tags for this Thread

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.