Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved How to join 2 QList and filter by QString ?

    General and Desktop
    2
    3
    1060
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • sonichy
      sonichy last edited by

      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")
      

      https://github.com/sonichy

      1 Reply Last reply Reply Quote 0
      • VRonin
        VRonin last edited by VRonin

        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);});
        

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply Reply Quote 2
        • sonichy
          sonichy last edited by

          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);
                  }
              }
          }
          

          https://github.com/sonichy

          1 Reply Last reply Reply Quote 0
          • First post
            Last post