PDA

View Full Version : QRegExpValidator not validating.



m3rlin
17th March 2013, 07:06
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.


QRegExp qrxRegEx( " Dunno what to do here to Validate for Hebrew Characters ");
QValidator* qValLineEdits;

qValLineEdits = new QRegExpValidator( qrxRegEx, this );
qValLineEdits->setLocale( QLocale::Hebrew );
QLocale qLocHeb = qValLineEdits->locale();

qDebug() << qLocHeb.name() << endl;

ui->leBugRepPersInfoName->setValidator( qValLineEdits );

d_stranz
17th March 2013, 16:03
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.

m3rlin
17th March 2013, 22:12
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.

d_stranz
17th March 2013, 22:43
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?

wysota
17th March 2013, 23:00
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:


QRegExp rx(QString::fromUtf8("[א-ת]+"));

or something like this.

ChrisW67
17th March 2013, 23:08
Hex form works fine here (my machine is an English locale):


#include <QtCore>
#include <QDebug>

int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);

QRegExp re("[\\x0590-\\x05ff]+");

wchar_t data[] = { 0x5E2, 0x5D1, 0x5E8, 0x5D9, 0x5EA, 0x0 };
QString inHebrew = QString::fromWCharArray(data);
qDebug() << inHebrew << "match at" << re.indexIn(inHebrew);

QString inEnglish("hebrew");
qDebug() << inEnglish << "match at" << re.indexIn(inEnglish); // no match

return 0;
}

m3rlin
18th March 2013, 06:17
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?

wysota
18th March 2013, 06:25
But he is also using a regular expression...

ChrisW67
18th March 2013, 07:37
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.