Guest User

Untitled

a guest
Jun 21st, 2012
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 1.40 KB | None | 0 0
  1. diff --git a/phyCounter.cpp b/phyCounter.cpp
  2. index 750f497..b6cc2e4 100644
  3. --- a/phyCounter.cpp
  4. +++ b/phyCounter.cpp
  5. @@ -1,6 +1,7 @@
  6.  #include "phyCounter.h"
  7. -
  8. +#include <QTimerEvent>
  9.  phyCounter::phyCounter(QObject *parent) : QObject(parent) {
  10. +   timerID_ = startTimer(1000);
  11.  }
  12.  
  13.  void phyCounter::startCount() {
  14. @@ -11,3 +12,12 @@ void phyCounter::startCount() {
  15.          dynamic_cast<phyThread*>(thread())->phySleep(1000);
  16.      }
  17.  }
  18. +
  19. +void phyCounter::timerEvent(QTimerEvent *)
  20. +{
  21. +   static int i=0;
  22. +   emit count(i++);
  23. +   if (i > 4) {
  24. +       killTimer(timerID_);
  25. +   }
  26. +}
  27. diff --git a/phyCounter.h b/phyCounter.h
  28. index d8a6502..6c530c4 100644
  29. --- a/phyCounter.h
  30. +++ b/phyCounter.h
  31. @@ -1,6 +1,8 @@
  32.  #include <QObject>
  33.  #include "phyThread.h"
  34.  
  35. +class QTimerEvent;
  36. +
  37.  class phyCounter : public QObject {
  38.      Q_OBJECT
  39.  public:
  40. @@ -8,4 +10,8 @@ public:
  41.      void startCount();
  42.  signals:
  43.      void count(int);
  44. +    protected:
  45. +       void timerEvent(QTimerEvent *);
  46. +   private:
  47. +       int timerID_;
  48.  };
  49. diff --git a/phyView.cpp b/phyView.cpp
  50. index 9c4cb81..a93f549 100644
  51. --- a/phyView.cpp
  52. +++ b/phyView.cpp
  53. @@ -15,7 +15,6 @@ phyView::phyView(QWidget *parent) : QGraphicsView(parent) {
  54.      phyCounter *counter = new phyCounter();
  55.      counter->moveToThread(thread);
  56.      connect(counter, SIGNAL(count(int)), this, SLOT(changeCount(int)));
  57. -    counter->startCount();
  58.  }
  59.  
  60.  phyView::~phyView() {
Advertisement
Add Comment
Please, Sign In to add comment