QT dialog close and delete

后端 未结 3 1735
走了就别回头了
走了就别回头了 2021-01-16 10:11

I have a MainWindow and Type class.

A button in the MainWindow sends a signal to a slot with this code:

dialog = new QDialog(this);

Ui_type typeui;
         


        
3条回答
  •  轮回少年
    2021-01-16 10:49

    You can set Qt::WA_DeleteOnClose attribute on your dialog. This will ensure that the dialog gets deleted whenever it is closed.

    Then call close() method in the dialog when your button is clicked.

    dialog = new QDialog(this);
    
    Ui_type typeui;
    typeui.setupUi(dialog);
    
    dialog->setAttribute(Qt::WA_DeleteOnClose);
    
    dialog->show();
    

    Refer to the documentation for details :

    QWidget::setAttribute ( Qt::WidgetAttribute attribute, bool on = true )

    Qt::WidgetAttribute

提交回复
热议问题