Now timer is working but cannot stop.
Qt Code:
  1. #include "form1.h"
  2. #include "ui_form1.h"
  3.  
  4.  
  5. #include <QTimer>
  6. #include <QTime>
  7.  
  8.  
  9. Form1::Form1(QWidget *parent) :
  10. QWidget(parent),
  11. ui(new Ui::Form1)
  12. {
  13. ui->setupUi(this);
  14.  
  15.  
  16. time.setHMS(0,0,0,0);
  17. i=0;
  18. ui->lcdNumber->setNumDigits(8);
  19. QString text = time.toString("hh:mm:ss");
  20. ui->lcdNumber->display(text);
  21. }
  22.  
  23. Form1::~Form1()
  24. {
  25. delete ui;
  26. }
  27.  
  28. void Form1::startTime()
  29. {
  30. QTimer *timer=new QTimer(this);
  31. connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));
  32. timer->start(1000);
  33. }
  34.  
  35. void Form1::showTime()
  36. {
  37. QTime newtime;
  38. i=i+1;
  39. newtime=time.addSecs(i);
  40. QString text = newtime.toString("hh:mm:ss");
  41. ui->lcdNumber->display(text);
  42.  
  43. }
  44.  
  45. void Form1::stopTime()
  46. {
  47. QTimer *timer=new QTimer(this);
  48. timer->stop();
  49. }
To copy to clipboard, switch view to plain text mode