0

I need to pass a filename as QString with path to a function covered in a QFuture and watched by a QFutureWatcher, but only the first character of this QString will be passed to this function. Here the declaration in the *.h file:

qint64 processDataFile(const QString &fileName);
...
QFutureWatcher<qint64> *watcher;

And here the call of the function:

watcher = new QFutureWatcher<qint64>;
    connect(watcher, &QFutureWatcher<qint64>::finished, this, &SmartDCPD::fileProcessingFinished);
    qDebug() << log.fileName; // something like C:/users/.....
    watcher->setFuture(QtConcurrent::mapped(log.fileName, std::bind(&SmartDCPD::processDataFile, this, std::placeholders::_1)));

And the code of the function:

qint64 SmartDCPD::processDataFile(const QString &fileName)
{
qDebug() << fileName; //Only C (just the first char of the whole QString)
QElapsedTimer t;
t.start();
rapidcsv::Document doc(fileName.toUtf8().constData(), rapidcsv::LabelParams(-1, -1), rapidcsv::SeparatorParams(';'));
QString stamp = QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss.zzz");
doc.SetCell<std::string>(1, 2, stamp.toUtf8().constData());
doc.Save();
return t.nsecsElapsed() / 1000000;
}

What am I doing wrong?

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
hkottmann
  • 1
  • 1
  • `mapped` takes as first argument sequence, and for every item of this sequence `functor` passed as second argument is called. So it works as expected, for every one single char `processDataFile` is called. If you want to call `processDataFile` for one input string containing the whole file path, you should create future by `QtConcurrent::run( std::bind(...) )`. – rafix07 Oct 12 '21 at 15:53
  • Thank you so much, you're great... – hkottmann Oct 12 '21 at 16:41

0 Answers0