Results 1 to 3 of 3

Thread: Window destructors and the destroy method

  1. #1
    Join Date
    Dec 2013
    Posts
    14
    Thanks
    6
    Qt products
    Qt5
    Platforms
    Windows

    Question Window destructors and the destroy method

    When accepting a closeEvent on a parentless window doing a destroy( true, true ) doesn't call the window's destructor.
    This can be fixed by explicitly calling the window's destructor in the closeEvent.

    Do I need to/should I call the destroy method in the destructor?

    If the window has a parent, and I force the window to close by calling the destructor, will the parent be notified of the close?
    If not, what do I need to to do to make sure the window is properly removed from the parent's child list?

    What documentation addresses this issue?

  2. #2
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Window destructors and the destroy method

    Too few info for giving some recommendation. Look at Qt::WA_DeleteOnClose and Qt::WA_QuitOnClose flags. Do not call dtors explicitly, it's an extra bad programming practice. Try to have your dtors called naturally, by your code logic.

    If the dtor was not called, the window was not destroyed. It was hidden. Is your main window a dialog or a frame window? How many top level windows do you have?

  3. #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: Window destructors and the destroy method

    Quote Originally Posted by sterling View Post
    When accepting a closeEvent on a parentless window doing a destroy( true, true ) doesn't call the window's destructor.
    The destructor calls destroy, so no need to call it yourself.

    Quote Originally Posted by sterling View Post
    This can be fixed by explicitly calling the window's destructor in the closeEvent.
    As Radek said, if you want a window to be destroyed on close, use the DeleteOnClose attribute.

    Quote Originally Posted by sterling View Post
    Do I need to/should I call the destroy method in the destructor?
    No, that's what the base implementation already does (as documented for QWidget::destroy())

    Quote Originally Posted by sterling View Post
    If the window has a parent, and I force the window to close by calling the destructor, will the parent be notified of the close?
    A parent QObject is always notified about a child's deletion. Otherwise it would attempt to delete it again upon its deletion.

    Cheers,
    _

Similar Threads

  1. Replies: 0
    Last Post: 8th March 2011, 22:08
  2. Calling a method to a parent window/widget
    By johnnyturbo3 in forum Newbie
    Replies: 4
    Last Post: 6th November 2010, 15:52
  3. Replies: 0
    Last Post: 2nd June 2009, 15:57
  4. Virtual destructors
    By jml in forum Qt Programming
    Replies: 6
    Last Post: 15th January 2008, 00:10
  5. Replies: 1
    Last Post: 24th June 2006, 20:55

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.