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] Validate inputs using QValidator class

[SOLVED] Validate inputs using QValidator class

Scheduled Pinned Locked Moved General and Desktop
qvalidatorforms
5 Posts 2 Posters 2.8k 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.
  • S Offline
    S Offline
    sachi
    wrote on 16 Aug 2015, 17:09 last edited by sachi
    #1

    Hello I am developing application which have many forms. I need to validate user input. I figure out QValidator is good solution for this. but I have many classes which has different forms. It is possible to use one QValidator class to validate all forms. Or I have to create QValidator object for every single input.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 16 Aug 2015, 17:58 last edited by
      #2

      Hi
      QValidator is (often) per Input
      but you can share one validator with more than one input
      if they have the same rules for acceptable input.

      But you cannot use one validator for a whole form since it has no way of knowing
      which rules for each input.

      The easiest way to set validation up, really depends on what types of input you have and how different they are.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sachi
        wrote on 16 Aug 2015, 18:21 last edited by
        #3

        I have usually text field for name which mush not null, and phone number and email. how i should start?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 16 Aug 2015, 18:44 last edited by
          #4

          Hi
          The validator work while user writes something so its hard to make it check for empty string so
          maybe just check that on "OK".

          For phone and email, you can use RegExpValidator.
          Please see
          http://stackoverflow.com/questions/9101887/how-to-validate-email-address-using-qregexp

          Its a bit complex to start with but once you get it up and running, you can just reuse the validator where needed.

          1 Reply Last reply
          1
          • S Offline
            S Offline
            sachi
            wrote on 16 Aug 2015, 19:08 last edited by
            #5

            Thank you for your help

            1 Reply Last reply
            0

            1/5

            16 Aug 2015, 17:09

            • Login

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