Try something like this. QtConcurrent will optimize the thread count.
void executeInProcess(QString& text)
{
QProcess::execute( "qconf", QStringList() << "-sq" << text);
}
void main()
{
QApplication app;
MainWindow mainWindow;
//...
QStringList queueList;
QFutureWatcher watcher;
connect(&watcher, SIGNAL(finished()), &mainWindow, SLOT(whatEverYouWantToDo()));
QFuture<void> result = QtConcurrent::map(queueList, executeInProcess);
watcher.setFuture(result);
//...
app.exec();
}
Edit
If you want result from every process you need the mapped function QFuture<T> mapped ( const Sequence & sequence, MapFunction function )
and executeInProcess needs to return the result from the QProcess
call.
QString executeInProcess(QString& text)
{
QString result;
QProcess::execute( "qconf", QStringList() << "-sq" << text);
// ...
return
}
in whatEverYouWantToDo()
you can iterate over the results
QFuture<QString> result ;
QFutureIterator<QString> i(result);
while (i.hasNext()) {
qDebug() << i.next();
}