If you need to run a function on a separate thread, you can use QtConcurrent
like this:
QtConcurrent::run(this, &Class1::b);
Edit: You can use QFutureSynchronizer
to wait for all threads, don't forget to allocate all threads using QThreadPool::globalInstance()->setMaxThreadCount()
.
Edit 2: You can use synchronizer.futures()
to acess all threads return values.
Example:
QThreadPool::globalInstance()->setMaxThreadCount(10);
QFutureSynchronizer<int> synchronizer;
for(int i = 1; i <= 10; i++)
synchronizer.addFuture(QtConcurrent::run(this, &Class1::b));
synchronizer.waitForFinished();
foreach(QFuture<int> thread, synchronizer.futures())
qDebug() << thread.result(); //Get the return value of each thread.