Why don't you use a QSemaphore? You instantiate it with n=0 (the default constructor).
Call sem.acquire(xxx.size()) to wait for all tasks to complete, amnd call sem.release(1) after each task completes. Best regards, Federico Ferri On Tue, Aug 17, 2021 at 9:03 PM Scott Bloom <sc...@towel42.com> wrote: > Here is the problem Im having. I have background task, that is small > enough to use a lambda on a given string. > > > > std::list< yyy > xxx; > > for( auto && ii : xxx ) > > { > QThreadPool::globalInstance()->start( > > [ii]() > > { > > doSomething( ii ); > > } ); > > } > > > > Works great for this… However, I want the application waiting until all > threads are completed before exiting the tool. > > > > while (QThreadPool::globalInstance()->activeThreadCount()) > > { > > QThreadPool::globalInstance()->waitForDone(100); > > qApp->processEvents(); > > } > > > > Should work. Wait 100ms, and continue. > > > > However, the problem Im having, is activeThreadCount does not take into > account queued threads. > > > > Is there a better way? The length of the xxx can be in the millions, and > is recursive. > > > Scott > > _______________________________________________ > Interest mailing list > Interest@qt-project.org > https://lists.qt-project.org/listinfo/interest >
_______________________________________________ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest