Hi,

I'm a relative newbie to Qt but am so far enjoying it. I have a question about QTimer. I have it working in an application but am just wondering if I am going about it the correct way.

Qt Code:
  1. #include "timerExample.h"
  2. #include <QtGui>
  3.  
  4. timerExample::timerExample(QWidget *parent, Qt::WFlags flags)
  5. : QWidget(parent, flags)
  6. {
  7. ui.setupUi(this);
  8. time = 0;
  9. timeInterval = 1; // this sets the time interval at 1 millisecond
  10. timer = new QTimer;
  11. connect(timer, SIGNAL(timeout()), this, SLOT(update()));
  12. }
  13.  
  14.  
  15. void timerExample::update()
  16. {
  17. time = time + timeInterval;
  18. }
  19.  
  20.  
  21. void timerExample::on_threadStartButton_clicked()
  22. {
  23. timer->start(timeInterval);
  24. }
  25.  
  26. void timerExample::on_threadStopButton_clicked()
  27. {
  28. timer->stop();
  29.  
  30. // writes out time taken to a LineEdit
  31. QString str = QString::number(time);
  32. ui.timeLine->setText(str);
  33. }
To copy to clipboard, switch view to plain text mode 


Is this the right way to use QTimer or am I missing something?