So how do I change values on other objects? For example, I need to update a QLabel everytime secondChanged signal is called.

My new code is:

timer.h
Qt Code:
  1. #ifndef Timer_H
  2. #define Timer_H
  3.  
  4. #include <QWidget>
  5. class QLabel;
  6.  
  7. class Timer : public QWidget
  8. {
  9. Q_OBJECT
  10.  
  11. public:
  12. Timer();
  13. int getHour();
  14. int getMinute();
  15. int getSecond();
  16.  
  17. int secondValue() const;
  18.  
  19. void show();
  20.  
  21. public slots:
  22. void addSecond();
  23.  
  24. signals:
  25. void secondChanged(int);
  26.  
  27. private:
  28. int hour;
  29. int minute;
  30. int second;
  31.  
  32. QLabel *l;
  33. };
  34.  
  35. #endif
To copy to clipboard, switch view to plain text mode 

-----------------------------------------------------------

timer.cpp
Qt Code:
  1. #include <QtGui>
  2. #include "timer.h"
  3.  
  4. Timer::Timer() : QWidget()
  5. {
  6. hour = 0;
  7. minute = 0;
  8. second = 0;
  9.  
  10. l = new QLabel();
  11. }
  12.  
  13. void Timer::addSecond()
  14. {
  15. second++;
  16. if(second == 60)
  17. {
  18. minute++;
  19. second = 0;
  20. if(minute == 60)
  21. {
  22. hour++;
  23. minute = 0;
  24. }
  25. }
  26. emit secondChanged(second);
  27. }
  28.  
  29. int Timer::getHour()
  30. {
  31. return hour;
  32. }
  33.  
  34. int Timer::getMinute()
  35. {
  36. return minute;
  37. }
  38.  
  39. int Timer::getSecond()
  40. {
  41. return second;
  42. }
  43.  
  44. int Timer::secondValue() const
  45. {
  46. return second;
  47. }
  48.  
  49. void Timer::show()
  50. {
  51. l->show();
  52. }
To copy to clipboard, switch view to plain text mode 

-----------------------------------------------

main.cpp
Qt Code:
  1. ...
  2. Timer *t = new Timer();
  3. QTimer *qTimer = new QTimer();
  4. QObject::connect(qTimer, SLOT(timeout()), t, SIGNAL(addSecond()));
  5. QObject::connect(t, SLOT(secondChanged(int)), l, SIGNAL(setNum(int)));
  6. qTimer->start(1000);
  7. l->show();
  8. ...
To copy to clipboard, switch view to plain text mode