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

即:

搞定,

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

相关推荐
xcyxiner2 天前
DicomViewer (dcmtk读取dcm文件)5
qt
xcyxiner2 天前
DicomViewer (后台线程处理文件)4
qt
xcyxiner3 天前
DicomViewer (添加模型类)3
qt
xcyxiner3 天前
DicomViewer (目录调整) 2
qt
xcyxiner4 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
桥田智能5 天前
桥田智能 QT-650S:面向白车身焊装的 800kg 重载快换解决方案
开发语言·qt·系统架构
森G5 天前
75、服务器源码解析---------云视频服务项目
linux·服务器·网络·c++·qt
森G6 天前
77、线程池原理和实现------服务器源码解析----云视频服务项目
服务器·c++·qt
森G6 天前
71、打包发布---------打包发布
c++·qt
初圣魔门首席弟子6 天前
Node.js 详细介绍(知识库版)
windows·qt·node.js·知识库