From 61d50f2668257e3c0b37a124ead491b3f53113b3 Mon Sep 17 00:00:00 2001 From: iridiumR Date: Tue, 29 Mar 2022 16:46:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SoftwareDesign/Code/2-2-5_enhanced/mainwindow.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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)); }