This commit is contained in:
iridiumR 2022-03-29 16:46:52 +08:00
parent 6acdb21e2d
commit 61d50f2668
1 changed files with 9 additions and 3 deletions

View File

@ -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));
}