Results 1 to 5 of 5

Thread: QRegularExpressionValidator: am I missing something?!

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QRegularExpressionValidator: am I missing something?!

    Note that I constructed the regular expression string using C++ string literal concatenation rather than your QString operators not that I expect that to be of any consequence.
    Indeed, I have just replaced 'my' version with yours and, as expected, it didn't make any difference.

    I say "runs fine" not "works fine" because the test string is a valid URL.
    Yes, everything runs fine indeed.

    Is there a reason you cannot use QUrl to do the validation work for you?
    Maybe, I am not sure. The fact is that I need the user to enter the URL. So, for this, I am using QLineEdit and I thought I would validate the user's entry as he enters it. Hence, my use QRegularExpressionValidator as a validator for QLineEdit. Now, are you implying that there is a way to achieve the same using QUrl as some kind of a validator? If so, I imagine that I would need to create my own validator and make it use QUrl to do the validation?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QRegularExpressionValidator: am I missing something?!

    The behaviour I see with your original code is that the line edit stops accepting more characters after the 20th 'u' is typed (making the total string length 26). It doesn't hang, backspace works for example. Once the validator stops returning Intermediate and starts returning Invalid the characters get dropped. A quick tweak of my code, shows the validator changing its mind:
    Qt Code:
    1. QString testString("http://");
    2. for (int i = 0; i < 32; ++i) {
    3. testString += "a";
    4. QRegularExpressionValidator validator(re);
    5. int pos = 0;
    6. qDebug() << (i+1) << testString << validator.validate(testString, pos);
    7. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. 1 "http://a" 1
    2. 2 "http://aa" 1
    3. 3 "http://aaa" 1
    4. 4 "http://aaaa" 1
    5. 5 "http://aaaaa" 1
    6. 6 "http://aaaaaa" 1
    7. 7 "http://aaaaaaa" 1
    8. 8 "http://aaaaaaaa" 1
    9. 9 "http://aaaaaaaaa" 1
    10. 10 "http://aaaaaaaaaa" 1
    11. 11 "http://aaaaaaaaaaa" 1
    12. 12 "http://aaaaaaaaaaaa" 1
    13. 13 "http://aaaaaaaaaaaaa" 1
    14. 14 "http://aaaaaaaaaaaaaa" 1
    15. 15 "http://aaaaaaaaaaaaaaa" 1
    16. 16 "http://aaaaaaaaaaaaaaaa" 1
    17. 17 "http://aaaaaaaaaaaaaaaaa" 1
    18. 18 "http://aaaaaaaaaaaaaaaaaa" 1
    19. 19 "http://aaaaaaaaaaaaaaaaaaa" 1
    20. 20 "http://aaaaaaaaaaaaaaaaaaaa" 1
    21. 21 "http://aaaaaaaaaaaaaaaaaaaaa" 0
    22. 22 "http://aaaaaaaaaaaaaaaaaaaaaa" 0
    23. 23 "http://aaaaaaaaaaaaaaaaaaaaaaa" 0
    24. 24 "http://aaaaaaaaaaaaaaaaaaaaaaaa" 0
    25. 25 "http://aaaaaaaaaaaaaaaaaaaaaaaaa" 0
    26. 26 "http://aaaaaaaaaaaaaaaaaaaaaaaaaa" 0
    27. 27 "http://aaaaaaaaaaaaaaaaaaaaaaaaaaa" 0
    28. 28 "http://aaaaaaaaaaaaaaaaaaaaaaaaaaaa" 0
    29. 29 "http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 0
    30. 30 "http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 0
    31. 31 "http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 0
    32. 32 "http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 0
    To copy to clipboard, switch view to plain text mode 
    It also gets progressively slower as the string gets longer. Even with 32 'a' chars, adding ".com" will validate (you cannot do it through the line edit though). I can see no reason for this behaviour. It might be some sort of recursion limit in the regex library.

    If so, I imagine that I would need to create my own validator and make it use QUrl to do the validation?
    Yes. Using QUrl will only give Invalid/Valid indication, where a QRegularExpression based approach can give an Intermediate indication for hasPartialMatch().

  3. #3
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QRegularExpressionValidator: am I missing something?!

    I tried the validation using QUrl and it's not sufficient for what I need. As you wrote, a QRegularExpression-based approach allows for intermediate state, which is useful. Also, I noticed that QUrl is too clever when it comes to validation. I mean that it will try to correct a user's mistake if it can. Anyway, QUrl validation is not an option.

    Regarding QRegularExpressionValidator, there is clearly something 'funny' going on, which is the reason I decided to create a bug report for it: https://bugreports.qt-project.org/browse/QTBUG-38034.

Similar Threads

  1. qgif.lib missing
    By stef13013 in forum Qt Programming
    Replies: 0
    Last Post: 18th September 2012, 22:17
  2. setCurveType missing in Qwt 6.0.1?
    By chinalski in forum Qwt
    Replies: 6
    Last Post: 26th February 2012, 15:36
  3. Mac OSX: missing executable ?
    By Hiwa in forum Qt Tools
    Replies: 2
    Last Post: 22nd April 2011, 15:02
  4. Qt Creator Help missing? (QT 2010.02)
    By Asperamanca in forum Qt Tools
    Replies: 0
    Last Post: 22nd July 2010, 08:56
  5. Missing tileVertically()
    By zarkzervo in forum Qt Programming
    Replies: 2
    Last Post: 3rd November 2009, 07:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.