应用场景:当界面运行后需要出现一个对话框,就选择创建dialog
dialog 分为模态和半模态
-
自定义对话框未关闭时,不可以对父窗口进行操作创造对话框对象后,与exec()配合使用,程序执行到exec()时,如果不对对话框进行操作,后面的代码不会执行。
-
当自定义对话框未关闭时,还可以对父窗口进行操作。常用于需要进行界面交互操作的情况
-
m_configurationDialog = new ParameterconfigurationDialog(this); m_configurationDialog->exec(); if (m_configurationDialog->result() == QDialog::Accepted) { m_configurationDialog->close(); m_sIp = m_configurationDialog->sIp(); m_dIp = m_configurationDialog->dIp(); m_agreement = m_configurationDialog->agreement(); m_number = m_configurationDialog->number(); m_port = m_configurationDialog->port(); CMDID::instance()->setcmdID(m_number); } else if (m_configurationDialog->result() == QDialog::Rejected) { delete m_configurationDialog;//删除对话框 return; } delete m_configurationDialog; void ParameterconfigurationDialog::on_pb_save_clicked() { m_sIp = ui->le_SystemIp->text(); m_dIp = ui->le_DeviceIp->text(); m_agreement = ui->cb_Agreement->currentText(); m_number = ui->le_Number->text(); m_port = ui->le_Port->text(); emit sigSendData(m_sIp, m_dIp, m_agreement, m_number); this->accept(); this->close(); }
当点击dialog右上角的x时,会自动触发reject()函数二、各种字符的相互转换