snctimer.cpp 661 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include "snctimer.h"
  2. SNCTimer::SNCTimer(int seconds,QObject *parent) :
  3. QThread(parent)
  4. {
  5. m_stop = false;
  6. m_seconds = seconds;
  7. }
  8. void SNCTimer::abort()
  9. {
  10. m_stop = true;
  11. }
  12. void SNCTimer::run()
  13. {
  14. m_stop = false;
  15. while(!m_stop)
  16. {
  17. QTime dieTime = QTime::currentTime().addMSecs(1000*m_seconds);
  18. QTime c;
  19. c.start();
  20. while( QTime::currentTime() < dieTime )
  21. {
  22. QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
  23. msleep(10);
  24. if(m_stop)
  25. break;
  26. }
  27. break;
  28. emit timerOut();
  29. }
  30. }