destructors in Qt4

后端 未结 5 1104
小鲜肉
小鲜肉 2020-12-31 11:17

I\'m very confused about using destructors in Qt4 and hope, you guys can help me.
When I have a method like this (with \"Des\" is a class):

void Widget::         


        
5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-31 12:05

    Another option to using deleteLater(), or parents, is to use the delete-on-close functionality for widgets. In this case, Qt will delete the widget when it is done being displayed.

    Des *test = new Des;
    test->setAttribute( Qt::WA_DeleteOnClose );
    test->show();
    

    I like to use it with the object tree that Qt keeps, so that I set delete-on-close for the window, and all widgets in the window have a proper parent specified, so they all get deleted as well.

提交回复
热议问题