return 项来自 QList<MyObject> 到文本字符串

return items from QList<MyObject> through text string

我需要在我的移动应用程序中进行查找。所以我有这个对象:

class Category
{
    public:
    Category();

    QString title;
    QString description;

};

在应用程序启动时,我从 json url 加载一些对象,并将它们放入 QList 列表中;

我已经完成了一种在我的 gui 上单击“查找”时更新模型的方法。

    void CategoryModel::searchByTextInCategoryList(QString testo)
    {
        QList<Category> lista = singleton::instance().categoryCompleteList;
        auto itObj = std::find_if(lista.begin(), lista.end(), [](Category o) { return o.title == "my searched text"; }); 
        //this not for me
    }

我需要类似的解决方案,如果可能的话:

QList<Category> result = lista.find_all.where(lista.at(index).title == "search text");

有这种可能性吗?

这个方法对我来说不太适用,因为我需要获取包含相同单词的所有对象。 能帮帮我吗? 我是C#过来的,在C#里我用的是Linq,QT里也有类似的linq可以在Qlist中按文本搜索?

简而言之...我需要在 QList 中进行查询并 return 列表中的多个项目。

谢谢

一个好的旧 foreach 怎么样?

void CategoryModel::searchByTextInCategoryList(QString testo)
{
    QList<Category> lista = singleton::instance().categoryCompleteList;
    QList<Category> results;
    foreach(Category c, lista) { 
        if (c.title.contains("my searched text"))
        //if (c.title. == "my searched text")
            results.append(c);
    }
}