[SOLVED] Validate inputs using QValidator class

  • 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.

  • Qt Champions 2016

    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.

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

  • Qt Champions 2016

    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

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

  • Thank you for your help

Log in to reply

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