Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to join 2 QList and filter by QString ?

How to join 2 QList and filter by QString ?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.5k Views
  • 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.
  • sonichyS Offline
    sonichyS Offline
    sonichy
    wrote on last edited by
    #1
    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
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      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
      2
      • sonichyS Offline
        sonichyS Offline
        sonichy
        wrote on last edited by
        #3
        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
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved