Results 1 to 4 of 4

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

  1. #1
    Join Date
    Jun 2015
    Location
    India
    Posts
    185
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default How to wait till all the Qt concurent threads finished with exec() and then continue

    I am running 5 threads as below

    Qt Code:
    1. void dialog::myfunction()
    2. {
    3. for(int i=0; i< 5 ; i++
    4. {
    5. QtConcurrent::run()
    6. }
    7.  
    8. QEventLoop l_event;
    9. i_event.exec()
    10.  
    11. qDebu() <<"All threads finished";
    12.  
    13. }
    To copy to clipboard, switch view to plain text mode 
    I want to wait here till all the threads get finished.

    Qt Code:
    1. void QFutureSynchronizer::waitForFinished () //is hanging my main GUI.
    To copy to clipboard, switch view to plain text mode 

    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 ?
    Last edited by prasad_N; 30th June 2015 at 11:53.
    Thanks :-)

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to wait till all the Qt concurent threads finished with exec() and then conti

    Quote Originally Posted by prasad_N View Post
    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 View Post
    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 View Post
    For some other reason I can not use QFutureWatcher().
    Why not? QtConcurrent::run() returns a QFuture

    Cheers,
    _

  3. #3
    Join Date
    Jun 2015
    Location
    India
    Posts
    185
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to wait till all the Qt concurent threads finished with exec() and then conti

    I did some thing like this.

    Qt Code:
    1. void dialog::myfunction()
    2. {
    3. for(int i=0; i< 5 ; i++
    4. {
    5. QtConcurrent::run()
    6. }
    7.  
    8. m_eventLoop= new QEventLoop(); //QPointer<QEventLoop> m_eventLoop; QPointer automatically make a pointer NULL when it gets deleted
    9. m_eventLoop->exec();
    10.  
    11. //do things after threads finished
    12.  
    13. qDebug() <<"All threads finished";
    14.  
    15. }
    16.  
    17.  
    18. void dialog::finishedAllThread()
    19. {
    20. if(m_eventLoop){
    21. m_eventLoop->quit();
    22. m_eventLoop->deleteLater();
    23. }
    24. }
    To copy to clipboard, switch view to plain text mode 


    //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.
    Last edited by prasad_N; 6th July 2015 at 21:02.
    Thanks :-)

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    _

Similar Threads

  1. How to wait till GUI contollers are changed?
    By IndikaU in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2011, 11:05
  2. Replies: 1
    Last Post: 6th September 2011, 08:34
  3. How to wait till QNetworkReply gives a result
    By Furkan in forum Qt Programming
    Replies: 3
    Last Post: 23rd November 2010, 11:00
  4. Replies: 8
    Last Post: 27th October 2009, 10:07
  5. How to wait 2 seconds before continue
    By raphaelf in forum Newbie
    Replies: 3
    Last Post: 25th June 2008, 15:36

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.