Unsolved Concurrently get contents of a folder
-
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?
-
@Akito_Kami Take a look at http://doc.qt.io/qt-5/qfilesystemwatcher.html
-
@jsulm I don't need to watch folders/files. I need to get a model of the folder contents.
-
@Akito_Kami Then maybe http://doc.qt.io/qt-5.7/qfilesystemmodel.html ?
-
@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?
-
@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);" -
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);
-
@jsulm Fixed it with changing QDir::Filters to QDir::Filter which is what I had before I tried QFlags but works now?
-
@Akito_Kami Is it a question? QDir::Filter is the enum yes.
-
@jsulm No it's not. Just wondering why it didn't work before.