[Qt-interest] How to stop all threads before quit?

sarvesh saran aquarian.thunder at gmail.com
Wed Mar 2 05:24:57 CET 2011


Hi,

you could reimplement close event in your window...from the close event stop
your worker thread....

QMainWindow::closeEvent(QCloseEvent *event)
{
//send a signal to the worker thread
workerThread->doRun(false);

while(! workerThread->isFinished()) { }

event->accept();
}

your thread should have a flag inside its run method:

void workerThread::run()
{
     while( ! doStop)
     {
         //do your stuff....
     }
}

you may want to read this article as well...
http://labs.qt.nokia.com/2006/12/04/threading-without-the-headache/

thanks,
Sarvesh




On Wed, Mar 2, 2011 at 7:57 AM, Nicholas Shatokhin <n.shatokhin at gmail.com>wrote:

> I'm creating a qt4 lib for using fingerprint scanner:
> https://github.com/NicholasShatokhin/fprint_qt
>
> Scanner working in thread. If user close window, thread still running and
> program finishing unexpectedly. So, how can I close all threads before
> exiting program?
>
> Best regards,
> Nick.
> --
> За використання революційного клієнта електронної пошти Opera:
> http://www.opera.com/mail/
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110302/77ea741f/attachment.html 


More information about the Qt-interest-old mailing list