diff --git a/SoftwareDesign/Code/2-2-5_enhanced/mainwindow.cpp b/SoftwareDesign/Code/2-2-5_enhanced/mainwindow.cpp index 4ae1ea6..0859933 100644 --- a/SoftwareDesign/Code/2-2-5_enhanced/mainwindow.cpp +++ b/SoftwareDesign/Code/2-2-5_enhanced/mainwindow.cpp @@ -22,8 +22,8 @@ void MainWindow::abortOperation() { result = 0.0; pendingOperator.clear(); ui->lineEdit->setText("0"); - waitForOperand = true; - QMessageBox::warning(this, "运算错误", "除数不能为零"); + isFinished = false; + QMessageBox::warning(this, "运算错误", "算式不合法"); } //数字被点击 @@ -55,7 +55,13 @@ void MainWindow::on_clearAllBtn_clicked() { } void MainWindow::on_equalBtn_clicked() { - result = cal(displayText.toStdString()); + try { + result = cal(displayText.toStdString()); + } + + catch (...) { + abortOperation(); + } isFinished = 1; ui->lineEdit->setText(QString::number(result)); }