Details
-
Bug
-
Resolution: Invalid
-
P3: Somewhat important
-
None
-
6.5.2
Description
The following regular expression matches everything that does not contain Chinese characters:
[^\u4e00-\u9fa5]* //Unicode 4e00 ~9fa5 is the range for most of Chinese characters. ^ to negate the whole range. * to match everything else.
It worked perfectly on C++ side, e.g. as regexp of a validator for QLineEdit. The QLineEdit then allows input of everything but Chinese. But not so on QML side.
The following QML code actually allows Chinese characters for TextInput but strangely not numbers:
TextInput {
id: input
anchors.fill: parent
anchors.margins: 1
//Extra backslash is used to escape otherwise QML complains about invalid format
validator: RegularExpressionValidator { regularExpression: /[^\\u4e00-\\u9fa5]*/ }
}
Temporary workaround:
1. Set validator from C++ side, e,g.
auto r = engine.rootObjects().at(0)->findChild<QRegularExpressionValidator*>("myRegexp"); r->setRegularExpression(QRegularExpression("[^\u4e00-\u9fa5]*"));
2. On QML side, use 'new' to create regexp instead of default // syntax, e.g.
regularExpression: new RegExp("[^\u4e00-\u9fa5]*")