如何使QDialogBu​​ttonBox不关闭其父QDialog?

时间:2010-07-16 03:13:35

标签: c++ qt dialog

我有一个带有QDialogBu​​ttonBox小部件的QDialog,我已经将按钮框的接受信号连接到我的QDialog子类中的一个插槽,如下所示:

void MyDialog::on_buttonBox_accepted()
{
    QString errorString = this->inputErrorString();
    if (errorString.isEmpty())
    {
        // Do work here
        // code code code...

        this->accept();
    }
    else
    {
        QMessageBox::critical(this, tr("Error"), tr("The following input errors have occurred:") + errorString);
    }
}

但是,在显示消息框后,对话框将关闭;显然按钮框自动将其接受的信号连接到QDialog的接受槽(我想手动调用该槽)。我该如何防止这种情况,以便采取上述手动方法?

1 个答案:

答案 0 :(得分:14)

您可以实现MyDialog :: accept()。该功能在QDialog中是虚拟的。