Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    [SOLVED] QComboBox with QIntValidator - better workaround

    General and Desktop
    2
    4
    1174
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F
      frankiefrank last edited by

      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.

      "Roads? Where we're going, we don't need roads."

      1 Reply Last reply Reply Quote 0
      • F
        frankiefrank last edited by

        Anyone got any tips for this?

        "Roads? Where we're going, we don't need roads."

        1 Reply Last reply Reply Quote 0
        • S
          Saugglocke last edited by

          Hey,

          simply switching from currentIndexChanged to activated should do the trick:

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

          bb

          1 Reply Last reply Reply Quote 0
          • F
            frankiefrank last edited by

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

            "Roads? Where we're going, we don't need roads."

            1 Reply Last reply Reply Quote 0
            • First post
              Last post