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. Concurrently get contents of a folder
Forum Updated to NodeBB v4.3 + New Features

Concurrently get contents of a folder

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 2.4k Views 1 Watching
  • 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.
  • Akito_KamiA Offline
    Akito_KamiA Offline
    Akito_Kami
    wrote on last edited by Akito_Kami
    #1

    I have an app which reads a folder structure containing files which are stored in the lowest level. I have a function that gets the contents of the path specified. I would like to concurrently run this function for every folder and generate a struct of each folder showing Name -> Date -> File List.

    Struct FSModel {
        QString name;
        QMap<QString, QVector<QString>> datedContents;
    }
    
    QVector<QString> getContents(const QFlag &type, const QString &path, void(*process)(QVector<QString>), int count=0)
    {
        QDir dir(path);
        QVector<QString> collection;
        QStringList temp = dir.entryList(QDir::NoDotAndDotDot, type);
        for (QString& str : temp)
        {
            collection << str;
            count += 1;
        }
        process(collection);
        return collection;
    }
    
    

    In the constructor,I have tried to call QtConcurrent::mappedReduced, to return a QPair<QString, QVector<QString> but receive an error for QFuture<QPair<...>> not being a scalar type. How should I load the folder structure into memory?

    jsulmJ VRoninV 2 Replies Last reply
    0
    • Akito_KamiA Akito_Kami

      I have an app which reads a folder structure containing files which are stored in the lowest level. I have a function that gets the contents of the path specified. I would like to concurrently run this function for every folder and generate a struct of each folder showing Name -> Date -> File List.

      Struct FSModel {
          QString name;
          QMap<QString, QVector<QString>> datedContents;
      }
      
      QVector<QString> getContents(const QFlag &type, const QString &path, void(*process)(QVector<QString>), int count=0)
      {
          QDir dir(path);
          QVector<QString> collection;
          QStringList temp = dir.entryList(QDir::NoDotAndDotDot, type);
          for (QString& str : temp)
          {
              collection << str;
              count += 1;
          }
          process(collection);
          return collection;
      }
      
      

      In the constructor,I have tried to call QtConcurrent::mappedReduced, to return a QPair<QString, QVector<QString> but receive an error for QFuture<QPair<...>> not being a scalar type. How should I load the folder structure into memory?

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Akito_Kami Take a look at http://doc.qt.io/qt-5/qfilesystemwatcher.html

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      Akito_KamiA 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Akito_Kami Take a look at http://doc.qt.io/qt-5/qfilesystemwatcher.html

        Akito_KamiA Offline
        Akito_KamiA Offline
        Akito_Kami
        wrote on last edited by
        #3

        @jsulm I don't need to watch folders/files. I need to get a model of the folder contents.

        jsulmJ 1 Reply Last reply
        0
        • Akito_KamiA Akito_Kami

          @jsulm I don't need to watch folders/files. I need to get a model of the folder contents.

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Akito_Kami Then maybe http://doc.qt.io/qt-5.7/qfilesystemmodel.html ?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • Akito_KamiA Akito_Kami

            I have an app which reads a folder structure containing files which are stored in the lowest level. I have a function that gets the contents of the path specified. I would like to concurrently run this function for every folder and generate a struct of each folder showing Name -> Date -> File List.

            Struct FSModel {
                QString name;
                QMap<QString, QVector<QString>> datedContents;
            }
            
            QVector<QString> getContents(const QFlag &type, const QString &path, void(*process)(QVector<QString>), int count=0)
            {
                QDir dir(path);
                QVector<QString> collection;
                QStringList temp = dir.entryList(QDir::NoDotAndDotDot, type);
                for (QString& str : temp)
                {
                    collection << str;
                    count += 1;
                }
                process(collection);
                return collection;
            }
            
            

            In the constructor,I have tried to call QtConcurrent::mappedReduced, to return a QPair<QString, QVector<QString> but receive an error for QFuture<QPair<...>> not being a scalar type. How should I load the folder structure into memory?

            VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            @Akito_Kami said in Concurrently get contents of a folder:

            in the constructor,I have tried to call QtConcurrent::mappedReduced

            could you show us your code?

            "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

            Akito_KamiA 1 Reply Last reply
            0
            • VRoninV VRonin

              @Akito_Kami said in Concurrently get contents of a folder:

              in the constructor,I have tried to call QtConcurrent::mappedReduced

              could you show us your code?

              Akito_KamiA Offline
              Akito_KamiA Offline
              Akito_Kami
              wrote on last edited by Akito_Kami
              #6

              @VRonin It didn't work because of QFuture requiring a scalar type and not being able to convert to non scalar type. I initially tried to return a QPair<QString, QVector<QString>> since QMaps didn't work but to no avail.

              On another note, how do you pass QDir::Filter which is either QDir::Files or QDir::Dirs to a function? I keep getting "error: no matching function for call to 'QDir::entryList(QDir::Filter&, QDir::Filter)'
              QStringList temp = dir.entryList(type, QDir::NoDotAndDotDot);"

              jsulmJ 1 Reply Last reply
              0
              • Akito_KamiA Akito_Kami

                @VRonin It didn't work because of QFuture requiring a scalar type and not being able to convert to non scalar type. I initially tried to return a QPair<QString, QVector<QString>> since QMaps didn't work but to no avail.

                On another note, how do you pass QDir::Filter which is either QDir::Files or QDir::Dirs to a function? I keep getting "error: no matching function for call to 'QDir::entryList(QDir::Filter&, QDir::Filter)'
                QStringList temp = dir.entryList(type, QDir::NoDotAndDotDot);"

                jsulmJ Online
                jsulmJ Online
                jsulm
                Lifetime Qt Champion
                wrote on last edited by jsulm
                #7

                @Akito_Kami

                QStringList QDir::entryList(Filters filters = NoFilter, SortFlags sort = NoSort) const
                

                so

                QStringList temp = dir.entryList(QDir::Files | QDir::NoDotAndDotDot);
                // or type if type holds QDir::Files or QDir::Dirs
                QStringList temp = dir.entryList(type | QDir::NoDotAndDotDot);
                

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                Akito_KamiA 1 Reply Last reply
                1
                • jsulmJ jsulm

                  @Akito_Kami

                  QStringList QDir::entryList(Filters filters = NoFilter, SortFlags sort = NoSort) const
                  

                  so

                  QStringList temp = dir.entryList(QDir::Files | QDir::NoDotAndDotDot);
                  // or type if type holds QDir::Files or QDir::Dirs
                  QStringList temp = dir.entryList(type | QDir::NoDotAndDotDot);
                  
                  Akito_KamiA Offline
                  Akito_KamiA Offline
                  Akito_Kami
                  wrote on last edited by
                  #8

                  @jsulm Fixed it with changing QDir::Filters to QDir::Filter which is what I had before I tried QFlags but works now?

                  jsulmJ 1 Reply Last reply
                  0
                  • Akito_KamiA Akito_Kami

                    @jsulm Fixed it with changing QDir::Filters to QDir::Filter which is what I had before I tried QFlags but works now?

                    jsulmJ Online
                    jsulmJ Online
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @Akito_Kami Is it a question? QDir::Filter is the enum yes.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    Akito_KamiA 1 Reply Last reply
                    1
                    • jsulmJ jsulm

                      @Akito_Kami Is it a question? QDir::Filter is the enum yes.

                      Akito_KamiA Offline
                      Akito_KamiA Offline
                      Akito_Kami
                      wrote on last edited by
                      #10

                      @jsulm No it's not. Just wondering why it didn't work before.

                      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