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

即:

搞定,

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

相关推荐
用户8055336980315 小时前
不止三件套:QObject 属性系统全关键字与运行时反射!
c++·qt
xcyxiner15 小时前
DicomViewer (vcpkg Windows和ubuntu编译)7
qt
Quz6 天前
QML Hello World 入门示例
qt
xcyxiner9 天前
DicomViewer (dcmtk读取dcm文件)5
qt
xcyxiner9 天前
DicomViewer (后台线程处理文件)4
qt
xcyxiner10 天前
DicomViewer (添加模型类)3
qt
xcyxiner10 天前
DicomViewer (目录调整) 2
qt
xcyxiner10 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
桥田智能12 天前
桥田智能 QT-650S:面向白车身焊装的 800kg 重载快换解决方案
开发语言·qt·系统架构
森G12 天前
75、服务器源码解析---------云视频服务项目
linux·服务器·网络·c++·qt