PDA

View Full Version : Question about exiting event loop



billy61
7th August 2009, 22:55
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:


void QMatrixApp::threadDone(int determinant, int threadID)
{
//out<<"finished, id: "<<threadID<<endl;
++this->threadFinCount;
this->determinants[threadID] = determinant;
if(threadFinCount == size){
int det = 0;
for(int i = 0; i < size; i++){
int temp = this->determinants[i]*this->matrix->matrix[0][i];
if(i % 2 == 1){
temp = -temp;
}
det += temp;
}
out<<det<<endl;
out<<"msec elapsed: "<<this->timer.elapsed()<<endl;
qApp->quit();
}

}

all that is really important out of this code is the last function call


qApp->quit();

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:


void QMatrixApp::singleThreadDet()
{
out<<"in single"<<endl;
out<<this->matrix->getDeterminant()<<endl;;
out<<"msec elapsed: "<<this->timer.elapsed()<<endl;
qApp->quit();
}

this function, just like the other one, calls


qApp->quit();

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?

caduel
8th August 2009, 09:11
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"