代码之家  ›  专栏  ›  技术社区  ›  Jake Petroules

如何使QDialogButtonBox不关闭其父QDialog?

  •  4
  • Jake Petroules  · 技术社区  · 14 年前

    我有一个带有QDialogButtonBox小部件的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 回复  |  直到 14 年前
        1
  •  14
  •   Maziyar Mk    9 年前

    可以实现MyDialog::accept()。函数在中是虚拟的 QDialog