【问题标题】:Qt QDialog with hide and WA_QuitOnClose带有隐藏和 WA_QuitOnClose 的 Qt QDialog
【发布时间】:2012-07-29 21:16:13
【问题描述】:

我有一个问题,我在 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;

main() 的行

这是为什么呢?在我读到的文档中, hide() 不应该返回任何东西。我正在使用 Qt 4.8.2

【问题讨论】:

    标签: c++ qt user-interface qdialog qtgui


    【解决方案1】:

    QDialog::setVisible(false) 确实会中断自己的事件循环,但您可以显式调用函数的基类版本QWidget::setVisible,以避免这种行为:

    void splashWin::show_About_Window()
    {
        MyAboutWindow win;
        QWidget::setVisible(false);
        win.exec();
        setVisible(true);
    }
    

    【讨论】:

      猜你喜欢
      • 2020-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-06
      相关资源
      最近更新 更多