Results 1 to 2 of 2

Thread: Question about exiting event loop

  1. #1
    Join Date
    Aug 2009
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Question about exiting event loop

    Hello all.
    I am currently writing an application that takes the determinant of matrices, and it has both a single-threaded and multi-threaded mode.

    My question is, once my application as finished, the method I use to exit the main event loop is not working.

    I connect the finished() signal to this slot for each of my worker threads in multithreaded mode:
    Qt Code:
    1. void QMatrixApp::threadDone(int determinant, int threadID)
    2. {
    3. //out<<"finished, id: "<<threadID<<endl;
    4. ++this->threadFinCount;
    5. this->determinants[threadID] = determinant;
    6. if(threadFinCount == size){
    7. int det = 0;
    8. for(int i = 0; i < size; i++){
    9. int temp = this->determinants[i]*this->matrix->matrix[0][i];
    10. if(i % 2 == 1){
    11. temp = -temp;
    12. }
    13. det += temp;
    14. }
    15. out<<det<<endl;
    16. out<<"msec elapsed: "<<this->timer.elapsed()<<endl;
    17. qApp->quit();
    18. }
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 
    all that is really important out of this code is the last function call
    Qt Code:
    1. qApp->quit();
    To copy to clipboard, switch view to plain text mode 
    when all of the threads are finished, this line executes, and the program terminates as one would expect it to.

    this is the code for the function that runs when the single-threaded mode is run:
    Qt Code:
    1. void QMatrixApp::singleThreadDet()
    2. {
    3. out<<"in single"<<endl;
    4. out<<this->matrix->getDeterminant()<<endl;;
    5. out<<"msec elapsed: "<<this->timer.elapsed()<<endl;
    6. qApp->quit();
    7. }
    To copy to clipboard, switch view to plain text mode 
    this function, just like the other one, calls
    Qt Code:
    1. qApp->quit();
    To copy to clipboard, switch view to plain text mode 
    when it is finished, but unlike the first function, the program does not terminate when I make this function call.

    Can anyone explain why, or lead me in the direction of how to resolve this?

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Question about exiting event loop

    maybe you have some more event loops running (perhaps a modal dialog?)
    use a debugger and break your programm after that call to qApp->quit() to see where the controlflow is "locked"

Similar Threads

  1. Replies: 0
    Last Post: 23rd October 2008, 12:43
  2. Qt plug-in for GLib event loop based application
    By profoX in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2008, 14:27
  3. Glib event loop
    By Brandybuck in forum Qt Programming
    Replies: 2
    Last Post: 28th September 2006, 17:19
  4. Workload in a QThread blocks main application's event loop ?
    By 0xBulbizarre in forum Qt Programming
    Replies: 14
    Last Post: 9th April 2006, 21:55
  5. Replies: 4
    Last Post: 23rd January 2006, 16:51

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
  •  
Qt is a trademark of The Qt Company.