【问题标题】:setFilterFixedString for multiple strings多个字符串的 setFilterFixedString
【发布时间】:2017-04-18 23:14:58
【问题描述】:

我的建议是: 有一种方法可以搜索两个或多个字符串(结果的并集) @ FILTRO->setFilterFixedString(searchText1); FILTRO->setFilterFixedString(searchText2); @ 我已经知道如何找到具有两个 Qstrings 的交集,或者只是其中一个,而不是具有一个字符串或另一个或两者的联合

谢谢

【问题讨论】:

    标签: c++ qt qsqltablemodel qsortfilterproxymodel


    【解决方案1】:

    您必须使用正则表达式来达到您的目的。试试setFilterRegExp 像这样:

    const QString firstString = "Hello";
    const QString secondString = "Bye";
    const QString exp = QString("/^.*?(?:\b|_)%1(?:\b|_).*?(?:\b|_)%2(?:\b|_).*?$/m").arg(firstString, secondString);
    QRegExp regExp(exp);
    

    现在在 QSortFilterProxyModel 类中使用这个表达式。

    我没有测试这个表达式,只是一个例子。您将在此链接中找到完整的解释:Regular expression to find two strings anywhere in input

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-30
      • 1970-01-01
      • 1970-01-01
      • 2013-03-14
      相关资源
      最近更新 更多