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}+$/

即:

搞定,

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

相关推荐
敲上瘾17 小时前
Qt控件通用属性:geometry、qrc资源到QSS样式表等
开发语言·c++·qt·ui
ShineWinsu19 小时前
对于Qt:QFontDialog的解析
c++·qt·面试·gui·字体·客户端·qfontdialog
JosieBook1 天前
【鸿蒙】把一个 Qt 桌面视频编辑器“搬“上鸿蒙 PC:Olive 移植适配全记录
qt·音视频·harmonyos
Lucas. Wáng2 天前
Qt学习之旅
c++·qt
金色熊族3 天前
qt5.15.9编译qt-creator7.0.2源码
linux·qt
ShineWinsu3 天前
对于Qt:QMessageBox的解析
开发语言·c++·qt·面试·客户端·qmessagebox·消息对话框
宏笋4 天前
Qt开发了一款绘图和制作信笺的软件
qt
半杯咖啡半行码4 天前
Qt 隐式共享(Implicit Sharing)深度解析:机制、陷阱与 Qt6迁移
开发语言·数据库·qt
慧都产品智能化5 天前
Qt 开发 CAD/CAM 工序表的隐性成本分析
c++·qt·qt5·qt6.3
ShineWinsu5 天前
对于Qt窗口:QMainWindow、QMenuBar、Qmenu、QAction的解析
c++·qt·菜单·qmainwindow·qaction·qmenu·qmenubar