How to join 2 QList and filter by QString ?



  • QDir dir1(path1);
    QFileInfoList list1 = dir1.entryInfoList();
    QDir dir2(path2);
    QFileInfoList list1 = dir2.entryInfoList();
    // How to add 2 QList and filter by member
    QFileInfoList list3 = list1 + list2;
    list3.filter(QFileInfoList::FileName, "dde")
    


  • I swear I'm not writing this horror on purpose

    QFileInfoList list3;
    list3.reserve(list1.size()+list2.size());
    for(const QFileInfoList& singleList : {qAsConst(list1),qAsConst(list2)})
    std::copy_if(singleList.cbegin(),singleList.cend(),std::back_inserter(list3),[](const QFileInfo& fileInfo)->bool{return fileInfo.fileName().contains(QStringLiteral("dde"),Qt::CaseInsensitive);});
    


  • QFileInfoList listSearch;
    QDir dir1(path1);
    QFileInfoList list1 = dir1.entryInfoList();
    QDir dir2(path2);
    QFileInfoList list1 = dir2.entryInfoList();
    QFileInfoList list3 = list1 + list2;
    
    void MainWindow::search(QString text)
    {
        listSearch.clear();
        for (int i=0; i<list3.size(); i++) {
            QFileInfo fileInfo = list3.at(i);
            if (fileInfo.fileName().contains(text,Qt::CaseInsensitive)) {
                listSearch.append(fileInfo);
            }
        }
    }
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.