使用currentIndex()或者currentText()

void Widget::calc()
{
    int first = ui->firstLineEdit->text().toInt();
    int second = ui->secondLineEdit->text().toInt();
    int result;
    switch(ui->comboBox->currentIndex())
    {
    case 0:
        result = first + second;
        ui->resultLineEdit->setText(QString::number(result));
        break;
    case 1:
        result = first - second;
        ui->resultLineEdit->setText(QString::number(result));
        break;
    case 2:
        result = first * second;
        ui->resultLineEdit->setText(QString::number(result));
        break;
    case 3:
        if(second != 0)
        {
            result = first / second;
            ui->resultLineEdit->setText(QString::number(result));
        }
        break;

    default:break;
    }

}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
  • 2021-05-15
猜你喜欢
  • 2021-04-12
  • 2022-12-23
  • 2022-12-23
  • 2021-05-21
  • 2021-06-13
  • 2021-07-13
  • 2021-09-11
相关资源
相似解决方案