#include #include #include #include #include #include #include using namespace std; int main(int argc, char **argv) { QCoreApplication app(argc, argv); typedef std::vector> VoidFutureVector; VoidFutureVector futures; QThreadPool::globalInstance()->setMaxThreadCount(200); int i; for (i = 0; i < 1000; ++i) { futures.emplace_back(QtConcurrent::run([i] { //cerr << "Starting DBusDaemonProcess " << i << endl; QProcess process; process.setProcessChannelMode(QProcess::ForwardedChannels); process.start("dbus-daemon", QStringList()<< "--session" << "--print-address" << "--address=tcp:host=localhost,port=0"); QTimer timer; QEventLoop eventloop; QObject::connect(&timer, SIGNAL(timeout()), &eventloop, SLOT(quit())); timer.setSingleShot(true); timer.start(1000); eventloop.exec(); process.kill(); process.waitForFinished(); cerr << "Stopping DBusDaemonProcess " << i << endl; })); } for (QFuture &future : futures) future.waitForFinished(); cerr << "Program done" << endl; }