How to organize multi-threaded file processing (opening, data collection, closing) from QFileInfoList array?
I found a sample code where you can just put it in 1 separate stream. And if for example files will be 20 or more, and you need to separate them, for example, into 4 streams.
dir.cd(pathFolder); dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks); QStringList nameFilter; nameFilter << "*.txt"; QFileInfoList list = dir.entryInfoList(nameFilter); This is what happens during processing. It simply reads 1 line, checks the match and adds it to the QTableWidget.
for (int i = 0; i < list.size(); ++i) { QFileInfo fileInfo = list.at(i); QFile file(fileInfo.filePath()); if (file.open(QIODevice::ReadOnly)) { QTextStream in(&file); QString line = in.readLine(); if(line.indexOf("str")!=-1) { ui->listWidget_ps->addItem(fileInfo.fileName()); } } }
QRunnableand company. - ixSci