本人最近使用Qt6.7.2编译CMAKE项目,主风格qml ,但在用TextField{}时却遇到了问题,
原本要求,编辑框只能输入中文汉字,
一听,很简单嘛,正则表达式:
一看,没毛病,老铁,但是,却达不到想要的效果,编辑框输入时,根本输入不了汉字,会一直报错:
QRegularExpressionPrivate::doMatch(): called on an invalid QRegularExpression object (pattern is '\A(?:^[\u4e00-\u9fa5]+$)\z')
QRegularExpressionPrivate::doMatch(): called on an invalid QRegularExpression object (pattern is '\A(?:^[\u4e00-\u9fa5]+$)\z')
QRegularExpressionPrivate::doMatch(): called on an invalid QRegularExpression object (pattern is '\A(?:^[\u4e00-\u9fa5]+$)\z')
QRegularExpressionPrivate::doMatch(): called on an invalid QRegularExpression object (pattern is '\A(?:^[\u4e00-\u9fa5]+$)\z')………………
这是为何呢?
废话不多说,
原因:[QTBUG-116808] QML does not handle regular expression as expected - Qt Bug Tracker
真正可行的是:
regularExpression: /^[\N{U+4e00}-\N{U+9fa5}]+$/
即:
搞定,
看来真正阻碍自己脚步的,并不是远处的高山,而是鞋里的一粒沙子……