Results 1 to 4 of 4

Thread: Qt::WA_DeleteOnClose

  1. #1
    Join Date
    Sep 2006
    Posts
    46
    Thanks
    2
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Qt::WA_DeleteOnClose

    Looking for confirmation on this attribute and garbage collection. If I do the following:

    Qt Code:
    1. QWidget *Qw = new QWidget();
    2.  
    3. Qw->setAttribute(Qt::WA_DeleteOnClose, true);
    4. qDebug() << testAttribute(Qt::WA_DeleteOnClose); // paranoid confirmation
    5.  
    6. Qw->close();
    7.  
    8. // At this point I can still access Qw without any errors
    9. qDebug() << Qw->baseSize(); // pick any access function
    To copy to clipboard, switch view to plain text mode 

    Now this code never crashes for me, my guess would be that garbage collection happens when time permits and the post close access is playing Russian roulette.

    Is this the correct assumption?
    Last edited by merlvingian; 22nd November 2006 at 18:12. Reason: typo

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Qt::WA_DeleteOnClose

    It will be deleted as soon as the control returns to the event loop. This is done by QObject::deleteLater().
    J-P Nurmi

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

    merlvingian (22nd November 2006)

  4. #3
    Join Date
    Sep 2006
    Posts
    46
    Thanks
    2
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt::WA_DeleteOnClose

    Along the same line of simplistic questions, if I have a signal/slot connection to a widget that is removed with a Qt::WA_DeleteOnClose is the connection automatically removed or would I have to manually disconnect it before the call to close?

    There should be no way to emit a signal since the widget is deleted but if it has slots connected from other widgets my guess is they would have to be disconnected to keep things tidy.

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Qt::WA_DeleteOnClose

    Yes, connections are cleaned up when any QObject is destroyed. See QObject::~QObject().
    J-P Nurmi

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.