QProcess inside QtConcurrent::mapped - no slots called
-
The following code works - "echo" program is called for "abc" and "def", the results are collected and printed.
If timer delay is set to 0, it stops working.
"echo" is called, even the readLine (if called) would return the right content, but "finished" slot is never called. process.state() shows that the process is still running.
Why?
QFuture<QString> tfuture; QFutureWatcher<QString> twatcher; QString ftest(QString a){ QProcess process; QEventLoop loop; QObject::connect(&process, &QProcess::finished, [&](int exit_code) { qDebug() << "OK " << a << " " << exit_code; loop.exit(0); }); QTimer::singleShot(1, [&] { qDebug() << "STARTING " << a; process.start("echo", {{"ECHO ", a}}); }); loop.exec(); return process.readLine(); }; void tfinished() { QList<QString> result = twatcher.future().results(); qDebug() << "finished " << result; } ... QStringList params = {{"abc", "def"}}; tfuture = QtConcurrent::mapped(params, ftest); connect(&twatcher, &QFutureWatcher<QString>::finished, this, &tfinished); twatcher.setFuture(tfuture); -
What exact Qt version do you use?