Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Any QValidator class in which I can pass QStringList as valid options.
Forum Update on Monday, May 27th 2025

Any QValidator class in which I can pass QStringList as valid options.

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 1.6k 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.
  • A Offline
    A Offline
    Ajay_11
    wrote on last edited by
    #1

    I have a QLineEdit editor along with QComboBox. Now I want that user can give only some of the pre-defined strings as value in QLineEdit. So is it possible that I pass that list as QStringList to QValidator class and then it checks for validation in that List.

    B 1 Reply Last reply
    1
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Not out of the box.

      But if you want the user to only enter a string that's in a list, why not use directly a QComboBox ? So no need to validate the input.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Ajay_11

        I have a QLineEdit editor along with QComboBox. Now I want that user can give only some of the pre-defined strings as value in QLineEdit. So is it possible that I pass that list as QStringList to QValidator class and then it checks for validation in that List.

        B Offline
        B Offline
        bharath144
        wrote on last edited by
        #3

        @Ajay_11
        I have a very similar need, kind of opposite to what your need is, I want the user to enter any text that's not one of the items in a QStringList. Were you able to achieve this? If you were, I could use your solution and add the negation of it myself.

        Cheers!
        ಮೈ ಗೋ ಭರತ ನಾರಾಯಣ
        Bharath Narayan M G

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Sounds like you should implement your own validator and check against a given list of words

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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