How to wait till all the Qt concurent threads finished with exec() and then continue
I am running 5 threads as below
Code:
void dialog::myfunction()
{
for(int i=0; i< 5 ; i++
{
QtConcurrent::run()
}
i_event.exec()
qDebu() <<"All threads finished";
}
I want to wait here till all the threads get finished.
Code:
void QFutureSynchronizer::waitForFinished () //is hanging my main GUI.
So I want to use some thing like this QEventLoop::exec(); But qDebug() is not getting called at all, Is there a way to reach qDebug() once all the threads finished.
For some other reason I can not use QFutureWatcher().
Any suggestions ?
Re: How to wait till all the Qt concurent threads finished with exec() and then conti
Quote:
Originally Posted by
prasad_N
I am running 5 threads as below
No, that schedules 5 tasks on the global thread pool.
Whether that gets executed by 5 threads or any other number depends on that thread pool.
Quote:
Originally Posted by
prasad_N
So I want to use some thing like this QEventLoop::exec(); But qDebug() is not getting called at all
There seems to be nothing that quits the even loop.
Quote:
Originally Posted by
prasad_N
For some other reason I can not use QFutureWatcher().
Why not? QtConcurrent::run() returns a QFuture
Cheers,
_
Re: How to wait till all the Qt concurent threads finished with exec() and then conti
I did some thing like this.
Code:
void dialog::myfunction()
{
for(int i=0; i< 5 ; i++
{
QtConcurrent::run()
}
m_eventLoop
= new QEventLoop();
//QPointer<QEventLoop> m_eventLoop; QPointer automatically make a pointer NULL when it gets deleted m_eventLoop->exec();
//do things after threads finished
qDebug() <<"All threads finished";
}
void dialog::finishedAllThread()
{
if(m_eventLoop){
m_eventLoop->quit();
m_eventLoop->deleteLater();
}
}
//I use QFutureWatcher, finished() signal to get to know when all the threads finished
//I can use QFutureWatcher actually, But I should not do things in slot instead I should do things in myfunction() only.
Re: How to wait till all the Qt concurent threads finished with exec() and then conti
Glad the read that you have solved the problem :)
Cheers,
_