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();
}
}
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();
}
}
To copy to clipboard, switch view to plain text mode
all that is really important out of this code is the last function call
qApp->quit();
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:
void QMatrixApp::singleThreadDet()
{
out<<"in single"<<endl;
out<<this->matrix->getDeterminant()<<endl;;
out<<"msec elapsed: "<<this->timer.elapsed()<<endl;
qApp->quit();
}
void QMatrixApp::singleThreadDet()
{
out<<"in single"<<endl;
out<<this->matrix->getDeterminant()<<endl;;
out<<"msec elapsed: "<<this->timer.elapsed()<<endl;
qApp->quit();
}
To copy to clipboard, switch view to plain text mode
this function, just like the other one, calls
qApp->quit();
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?
Bookmarks