[SOLVED] QComboBox with QIntValidator - better workaround



  • When working with the QSerialPort Terminal example,I encountered a QComboBox with a "Custom" option - allowing the user to insert custom values checked by a validator:

    http://qt-project.org/doc/qt-5/qtserialport-terminal-settingsdialog-cpp.html

    In short, the combo box includes a Custom item and when that is selected (checked every time currentIndexChanged signal is emitted), the lineEdit is cleared and the validator is set.

    However, there's a problem here. If after selecting Custom (which triggers the code that clears the lineEdit) I were to reselect Custom, the "Custom" value will be copied to the lineEdit and the validator stops working. This means that I can enter any incorrect string after that.

    That second selection doesn't cause another currentIndexChanged signal, which makes sense since we didn't really change the selected index. I considered removing the Custom option from the combo when in combo box, but that DOES emit the index changed signal and creates a bigger mess as the first item is then selected by default.

    I was wondering if there's a nice "complete" workaround for this Custom value scenario as the version in that sample obviously has this bug.



  • Anyone got any tips for this?



  • Hey,

    simply switching from currentIndexChanged to activated should do the trick:

    @ connect(ui->baudRateBox, SIGNAL(activated(int)),
    this, SLOT(checkCustomBaudRatePolicy(int)));@

    bb



  • Thank you very much, Saugglocke - this solved my issue!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.