Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QComboBox with QIntValidator - better workaround
QtWS25 Last Chance

[SOLVED] QComboBox with QIntValidator - better workaround

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.5k Views
  • 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 Offline
    F Offline
    frankiefrank
    wrote on last edited by
    #1

    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
    0
    • F Offline
      F Offline
      frankiefrank
      wrote on last edited by
      #2

      Anyone got any tips for this?

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Saugglocke
        wrote on last edited by
        #3

        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
        0
        • F Offline
          F Offline
          frankiefrank
          wrote on last edited by
          #4

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

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved