Qt6 QML RegularExpressionValidator 输入中文的坑

本人最近使用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}+$/

即:

搞定,

看来真正阻碍自己脚步的,并不是远处的高山,而是鞋里的一粒沙子......

相关推荐
小鱼仙官12 小时前
Qt 主界面弹出分界面
开发语言·qt
誰能久伴不乏16 小时前
用 UDP 做一条“可靠“的控制通道
c++·qt·网络协议·udp
Bczheng120 小时前
VS2022 安装MFC和QT
c++·qt·mfc
会编程的小孩21 小时前
8.19号函数
qt
蓝祁子yoky2 天前
Qt学习日记 Day15:网络编程(二)- UDP基础
网络·qt·学习
读书札记20222 天前
Qt UTF-8和UTF-8(BOM)
开发语言·qt
ShineWinsu2 天前
对于Qt:QProgressBar常见属性的解析
开发语言·c++·qt·进度条·gui·定时器·qprogressbar
ShineWinsu2 天前
对于Qt:QLCDNumber常见属性以及QTimer的解析
服务器·数据库·c++·qt·gui·qtimer·qlcdnumber
听风吹等浪起2 天前
第26章:ViT+InceptionDW+FocalLoss改进|CT骨折影像二分类完整Pytorch实现(含PyQt5推理GUI)
pytorch·qt·分类
ShineWinsu2 天前
对于Qt:QRadioButton常见属性以及QButtonGroup的解析
数据库·c++·qt·microsoft·gui·qradiobutton·qbuttongroup