Does Qt have a similar way to create multiple threads?

for (int i = 0; i < iThreadCount; ++i) { threads.push_back(boost::thread(func)); } 

    2 answers 2

    Qt has QThreadPool and QtConcurrent .

    For example, QtConcurrent::map :

     struct Task { int i; } int foo(const Task& t) { return ti * ti; } QVector<Task> tasks; tasks << Task{2} << Task{4}; QFuture<int> future = QtConcurrent::map(tasks, foo); future.waitForFinished(); 

    The results of executing foo() in future.results() .

    • Complete your answer with a code or a more detailed answer. Now your answer looks like a comment - Yuri

    1) Thread Pool :

     class Thread : public QRunnable{ void run(){ func(); } }; //... for (int i = 0; i < iThreadCount; ++i) { QThreadPool::globalInstance()->start(new Thread); } 

    2) QtConcurrent :: run

     //вместо void тип возвращаемого значения func QVector<QFuture<void> > futures; for (int i = 0; i < iThreadCount; ++i) { futures.append(QtConcurrent::run(func)); }