Results 1 to 9 of 9

Thread: QRegExpValidator not validating.

  1. #1
    Join Date
    Dec 2011
    Posts
    36
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question QRegExpValidator not validating.

    Hi,

    I am experiencing some difficulties to correctly using validation on a QLineEdit for Hebrew Character Classes.
    I have tried using the UTF Range with \u0590-\u05FF or \x0590-\x05FF and scripts like \p{Hebrew} or \p{InHebrew}.
    I also guestimated the eating of backslashes so I tried \\ double slash and even an actual slash with \\\\.
    At one point, I wondered if I needed to install PCRE support, but then assumed that I don't need to conform with Perl Style validation so I left that subject.
    I have set the QRegExpValidator to using the QLocale::Hebrew (and get a proper response: the Israeli country code ).
    Whatever I have tried so far doesn't validate any Hebrew characters in a QLineEdit.

    I am using KDE/Linux with Hebrew Language support. My default system locale = en-US.
    My Qt version is 4.8.0. 32-bit with Creator 2.4.1

    Maybe I am missing something, and someone could point me into the correct direction? Below is the validation code that I attempted. I left the RegEx's out, since I mentioned them above.

    Qt Code:
    1. QRegExp qrxRegEx( " Dunno what to do here to Validate for Hebrew Characters ");
    2. QValidator* qValLineEdits;
    3.  
    4. qValLineEdits = new QRegExpValidator( qrxRegEx, this );
    5. qValLineEdits->setLocale( QLocale::Hebrew );
    6. QLocale qLocHeb = qValLineEdits->locale();
    7.  
    8. qDebug() << qLocHeb.name() << endl;
    9.  
    10. ui->leBugRepPersInfoName->setValidator( qValLineEdits );
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QRegExpValidator not validating.

    So if you forget about setting the Hebrew locale for the time being and just try to validate using English input for an English reg exp, does that work? You have to differentiate first between an improperly configured validator and the locale / character set issue.

  3. #3
    Join Date
    Dec 2011
    Posts
    36
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QRegExpValidator not validating.

    Hey d_stranz,

    Yes English validation works on either Locale, strange enough. It looks like the UTF character range is not recognized or initialized. That's why I thought that I needed Perl style RegEx for Qt.
    But reading other replies on Google, QtProject, QtCentre and such forums, PCRE support for e.g. Vietnamese isn't required... I also need to mention that the dialog uses right to left and QLocale Israel and Hebrew (country settings). SO I tried RegEx without utf but nothing seems to recognize the character set. Could it be related to using the Standard Ubuntu Font 9 and not some Hebrew font? I have't tried that.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QRegExpValidator not validating.

    I've pretty much reached the end of my knowledge here - I have no experience with right-to-left reading languages. Vietnamese, e.g., is left-to-right reading. A wild shot: do you need to express the reg exp as right to left or vice-versa?

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QRegExpValidator not validating.

    Right-to-left is only about display, it has no influence on input.

    It would be easier to understand what the whole validation is all about in this particular case. If the requirement is that all characters the user enters need to be hebrew glyphs then what seems easiest is to provide a range of accepted characters. Just remember about whitespaces and such which probably should be accepted as well. A first try would be:

    Qt Code:
    1. QRegExp rx(QString::fromUtf8("[א-ת]+"));
    To copy to clipboard, switch view to plain text mode 

    or something like this.
    Last edited by wysota; 17th March 2013 at 23:05.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    m3rlin (18th March 2013)

  7. #6
    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: QRegExpValidator not validating.

    Hex form works fine here (my machine is an English locale):
    Qt Code:
    1. #include <QtCore>
    2. #include <QDebug>
    3.  
    4. int main(int argc, char **argv)
    5. {
    6. QCoreApplication app(argc, argv);
    7.  
    8. QRegExp re("[\\x0590-\\x05ff]+");
    9.  
    10. wchar_t data[] = { 0x5E2, 0x5D1, 0x5E8, 0x5D9, 0x5EA, 0x0 };
    11. QString inHebrew = QString::fromWCharArray(data);
    12. qDebug() << inHebrew << "match at" << re.indexIn(inHebrew);
    13.  
    14. QString inEnglish("hebrew");
    15. qDebug() << inEnglish << "match at" << re.indexIn(inEnglish); // no match
    16.  
    17. return 0;
    18. }
    To copy to clipboard, switch view to plain text mode 

  8. The following user says thank you to ChrisW67 for this useful post:

    m3rlin (18th March 2013)

  9. #7
    Join Date
    Dec 2011
    Posts
    36
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QRegExpValidator not validating.

    Thanks Guys for resetting my brain. In all them +20k lines that I wrote so far, I am using QString::fromUtf8... I dunno why I didn't mentally connect the need for using QString::fromUtf8 in the RegEx statement. I should have posted the RegEx's as well. Doh!

    Is there a small performance penalty using RegEx over using Chris his solution (which works too....)? I remember reading that RegEx is generally slowing down your app?

  10. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QRegExpValidator not validating.

    But he is also using a regular expression...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #9
    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: QRegExpValidator not validating.

    The only difference is in construction time for the QRegExp, which will generally be dwarfed by the execution time for any non-trivial regular expression. If you are going to run the expression frequently, say in a tight loop, then you would arrange to construct the object once and keep it.

  12. The following user says thank you to ChrisW67 for this useful post:

    m3rlin (18th March 2013)

Similar Threads

  1. editing string in QLineEdit with QRegExpValidator
    By Al_ in forum Qt Programming
    Replies: 0
    Last Post: 28th April 2012, 10:51
  2. Memory leak in QRegExpValidator?!?
    By Tiansen in forum Qt Programming
    Replies: 1
    Last Post: 28th December 2009, 14:17
  3. Mixing QRegExpValidator and input mask and QLineEdit
    By abernat in forum Qt Programming
    Replies: 1
    Last Post: 18th February 2009, 00:04
  4. Validating QLineEdit
    By OriginalCopy in forum Qt Programming
    Replies: 2
    Last Post: 8th November 2007, 17:12
  5. QRegExpValidator
    By TheKedge in forum Qt Programming
    Replies: 2
    Last Post: 28th February 2007, 14:07

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.