【问题标题】:Search for UTF encoded characters using QRegExp使用 QRegExp 搜索 UTF 编码的字符
【发布时间】:2014-09-05 07:55:24
【问题描述】:

我正在尝试使用 QRegExp 检查字符 §£¤。

QString string = "§¤£";
int res = string.count(QRegExp("[§¤£]"));

res 返回 0。

【问题讨论】:

    标签: regex qt utf-8 qregexp


    【解决方案1】:

    编辑您的 .pro 文件并设置以下内容:

    CODECFORSRC = UTF-8
    CODECFORTR = UTF-8
    

    然后添加到您的 .cpp 文件中:

    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
    

    如果您需要,它将为您的源代码和国际化提供 UTF-8 支持。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-13
      • 1970-01-01
      • 2020-09-20
      • 2012-10-12
      • 1970-01-01
      • 1970-01-01
      • 2013-03-19
      • 1970-01-01
      相关资源
      最近更新 更多