QT对话框关闭和删除 [英] QT dialog close and delete
问题描述
我有一个MainWindow和Type类。
I have a MainWindow and Type class.
MainWindow中的一个按钮发送一个信号到一个插槽用这个代码:
A button in the MainWindow sends a signal to a slot with this code:
dialog = new QDialog(this);
Ui_type typeui;
typeui.setupUi(dialog);
dialog->show();
然后会显示对话框。当一个按钮被点击对话框,我想关闭对话框并删除它。
The dialog then shows. When a button is clicked on the dialog, I want to close the dialog and delete it.
我不明白如何从对话框中引用对话框。
I don't understand how to refer to the dialog from the dialog itself.
任何帮助将不胜感激。感谢。
Any help would be appreciated. Thanks.
推荐答案
您可以设置 Qt :: WA_DeleteOnClose
对话。这将确保该对话框在被关闭时被删除。
You can set Qt::WA_DeleteOnClose
attribute on your dialog. This will ensure that the dialog gets deleted whenever it is closed.
然后在单击按钮时在对话框中调用 close()
方法。
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对话框关闭和删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!