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. QValidator manual validation.
Forum Updated to NodeBB v4.3 + New Features

QValidator manual validation.

Scheduled Pinned Locked Moved Unsolved General and Desktop
qvalidator
4 Posts 2 Posters 2.2k Views 1 Watching
  • 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.
  • K Offline
    K Offline
    Kaluss
    wrote on last edited by
    #1

    Hi,
    I got problem with manual validation of handled text.

    I got situation where I take validator for QLineEdit::validator() and I want to check if my current text is passing validators conditions.

    For e.g.
    1)I set validator

    this->edit1->setValidator(new QRegExpValidator(QRegExp("[A-Za-z]{5}"),this));//no more than 5 letter character
    

    2)When I try to access this validator from the pointer to QlineEdit and execute QValidator::validate(text, pos(0))
    for:

    1. "a" i get QValidator::Intermediate (should be QValidator::Acceptable)
    2. "aa" I get QValidator::Intermediate (should be QValidator::Acceptable)
    3. "aaa" I get QValidator::Intermediate (should be QValidator::Acceptable)
    4. "aaaa" I get QValidator::Intermediate (should be QValidator::Acceptable)
    5. "aaaaa" I get QValidator::Invalid (should be QValidator::Acceptable)

    Do I get something wrong?
    How to use that validation?
    If I not able to validate handled text by this method could anyone say how can I do that?

    Best regards,
    Tomek

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      {5} means "exactly 5 times" so the fist 4 strings will be partial matches (intermediate state).
      to have "no more than 5" use {0,5}.

      As for the last case - it returns Acceptableto me as expected. Can you show the code that calls validate()? Also what is text and pos(0)?

      As a side note - you should switch to QRegularExpressionValidator if possible. It uses the recommended, Perl compatible, replacement of QRegExp - QRegularExpression.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Kaluss
        wrote on last edited by
        #3

        Hi,
        You are completely right. I was wrong with assumption that {5} means no more than five.

        Text is some text. pos(0) means that I put there 0 value, but do You maybe know whats that parameter really do?

        Best regards,
        Tomek

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Kaluss said:

          but do You maybe know whats that parameter really do?

          It's suppose to be "cursor position", but in case of regexp validator it's really a useless parameter to satisfy the interface of QValidator. It gets set to the length of the string if the regexp validator doesn't find a match.

          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