PDA

View Full Version : How to wait till all the Qt concurent threads finished with exec() and then continue



prasad_N
30th June 2015, 11:36
I am running 5 threads as below




void dialog::myfunction()
{
for(int i=0; i< 5 ; i++
{
QtConcurrent::run()
}

QEventLoop l_event;
i_event.exec()

qDebu() <<"All threads finished";

}

I want to wait here till all the threads get finished.


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 ?

anda_skoa
30th June 2015, 12:23
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.



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.


For some other reason I can not use QFutureWatcher().

Why not? QtConcurrent::run() returns a QFuture

Cheers,
_

prasad_N
6th July 2015, 19:17
I did some thing like this.


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.

anda_skoa
6th July 2015, 19:23
Glad the read that you have solved the problem :)

Cheers,
_