How can I wait for the finish of a QThread or What is the equivalent of std::thread::join() method in QThread
In std::thread, I can do it like the following
void foo()
{
// simulate expensive operation
std::cout << "starting first thread1...\n";
std::this_thread::sleep_for(std::chrono::seconds(1));
}
void bar()
{
// simulate expensive operation
std::cout << "starting second thread2...\n";
std::this_thread::sleep_for(std::chrono::seconds(1));
}
int main()
{
std::thread thread1(foo);
std::thread thread2(bar);
std::cout << "waiting for threads to finish..." << std::endl;
thread1.join();
thread2.join();
std::cout << "done!\n";
}
The output gives the following output:
starting first thread1...
waiting for threads to finish...
starting second thread2...
done!