Qt qdialog与hide和wa_quitonclose
-
13-12-2019 - |
题
我有问题,我在main()中称为我的qdialog:
app.setQuitOnLastWindowClosed(true);
splashWin startWin;
if(!startWin.exec())
{
// Rejected
return EXIT_SUCCESS;
}
// Accepted, retrieve the data
startWin.myData...
.
和在qdialog中,我有以下代码:
splashWin::splashWin(QWidget *parent) :
QDialog(parent),
ui(new Ui::splashWin)
{
ui->setupUi(this);
this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
this->setAttribute(Qt::WA_QuitOnClose);
}
void splashWin::on_OK_clicked()
{
// Prepare my data
..
accept();
}
void splashWin::show_About_Window()
{
MyAboutWindow win;
setVisible(false); // <- this causes the application to send a "reject" signal!! why??
win.exec();
setVisible(true);
}
.
这是一个非常简单的代码,问题是:setvisible(false)或hide()行显示关于窗口,但一旦窗口被忽略了“拒绝”对话框,我的应用程序关闭了执行
// Rejected
return EXIT_SUCCESS;
.
主要()
为什么?在文档中,我读取该隐藏()不应该返回任何内容。我正在使用Qt 4.8.2
解决方案
QDialog::setVisible(false)
会中断其自己的事件循环,但您可以明确调用函数的基类版本,而是避免该行为:
void splashWin::show_About_Window()
{
MyAboutWindow win;
QWidget::setVisible(false);
win.exec();
setVisible(true);
}
. 不隶属于 StackOverflow