Thread not exiting
Yes, I assumed you did so.
Add the mCancelled member and replace the two "while" conditions with:
1. The first while:
2. The second while:
Declare mCancelled in the thread class as ( you can make it private ):
Also, add a new member function( public ):
All you have to do next is to call cancelThread instead of quit().
Note that it may take a little for the thread to stop, because it may be inside one of the loops when you set mCanceled to true. But this delay is acceptable, in my opinion, and you may not even notice it.
EDIT - Don;t forget to make mCancelled false in the constructor of the thread
Add the mCancelled member and replace the two "while" conditions with:
1. The first while:
Qt Code:
while( !mCanceled )
Qt Code:
while( numMsgs && !mCancelled )
Qt Code:
volatile bool mCancelled;
Qt Code:
void cancelThread(); ... void CanRead::cancelThread() { mCancelled = true; }
Note that it may take a little for the thread to stop, because it may be inside one of the loops when you set mCanceled to true. But this delay is acceptable, in my opinion, and you may not even notice it.
EDIT - Don;t forget to make mCancelled false in the constructor of the thread
No comments:
Post a Comment