Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QComboBox(property "currentindex")



  • There are two spinboxes and a combo box on the form. The task is the following: enter the data in the spinbox1-> select the value from the combo box-> in the spinbox2, depending on the selection in the combobox, the recalculated value is written.
    How to implement using signals and slots?
    0_1527749614694_111111.PNG



  • Hi @fender
    In Qt Create Design, You should see "signals&slots Editor". mostly it will be at the bottom. you can add signals from sender to receiver. use "valueChanged()" signal for spin box and combobox. once it calls the receiver, calculate using formula by considering both spin1 and combobox values. Hope this helps

    -Tirupathi



  • @Tirupathi-Korla said in QComboBox(property "currentindex"):

    Hi @fender
    In Qt Create Design, You should see "signals&slots Editor". mostly it will be at the bottom. you can add signals from sender to receiver. use "valueChanged()" signal for spin box and combobox. once it calls the receiver, calculate using formula by considering both spin1 and combobox values. Hope this helps

    -Tirupathi
    implemented like this

        double d_mu = ui->doubleSpinBox_dmu->value();
        double ro_water = ui->doubleSpinBox_ro_water->value();
        switch(ui->cbTransfer->currentIndex()){
        case 0:  ui->doubleSpinBox_mu->setValue(calc_m2c(d_mu));    break;
        case 1:  ui->doubleSpinBox_mu->setValue(calc_mm2c(d_mu));   break;
        case 2:  ui->doubleSpinBox_mu->setValue(calc_Ct(d_mu));     break;
        case 3:  ui->doubleSpinBox_mu->setValue(calc_P(d_mu, ro_water)); break;
        case 4:  ui->doubleSpinBox_mu->setValue(calc_Pas(d_mu, ro_water));break;
        }
        connect(ui->doubleSpinBox_mu, SIGNAL(valueChanged(double)), SLOT(on_cbTransfer_currentIndexChanged));
    
    

Log in to reply