hi
form1.h
#ifndef FORM1_H
#define FORM1_H
#include <QString>
#include <QWidget>
#include <QTimer>
#include <QTime>
namespace Ui {
class Form1;
}
{
Q_OBJECT
public:
explicit Form1
(QWidget *parent
= 0);
~Form1();
int i;
private:
Ui::Form1 *ui;
private:
public slots:
void startTime();
void showTime();
void stopTime();
};
#endif // FORM1_H
#ifndef FORM1_H
#define FORM1_H
#include <QString>
#include <QWidget>
#include <QTimer>
#include <QTime>
namespace Ui {
class Form1;
}
class Form1 : public QWidget
{
Q_OBJECT
public:
explicit Form1(QWidget *parent = 0);
~Form1();
int i;
private:
Ui::Form1 *ui;
private:
QTime time;
QTimer timer;
public slots:
void startTime();
void showTime();
void stopTime();
};
#endif // FORM1_H
To copy to clipboard, switch view to plain text mode
form1.cpp
#include "form1.h"
#include "ui_form1.h"
#include <QTimer>
#include <QTime>
ui(new Ui::Form1)
{
ui->setupUi(this);
ui->lcdNumber->setNumDigits(8);
time.setHMS(0,0,0,0);
connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));
i=0;
QString text
= time.
toString("hh:mm:ss");
ui->lcdNumber->display(text);
}
Form1::~Form1()
{
delete ui;
}
void Form1::startTime()
{
timer.start();
}
void Form1::showTime()
{
newtime.setHMS(0,0,0,0);
i=i+1;
newtime=time.addSecs(i);
QString text
= newtime.
toString("hh:mm:ss");
ui->lcdNumber->display(text);
}
void Form1::stopTime()
{
timer.stop();
}
#include "form1.h"
#include "ui_form1.h"
#include <QTimer>
#include <QTime>
Form1::Form1(QWidget *parent) :
QWidget(parent),
ui(new Ui::Form1)
{
ui->setupUi(this);
ui->lcdNumber->setNumDigits(8);
QTime time = QTime();
time.setHMS(0,0,0,0);
QTimer *timer=new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));
i=0;
QString text = time.toString("hh:mm:ss");
ui->lcdNumber->display(text);
}
Form1::~Form1()
{
delete ui;
}
void Form1::startTime()
{
timer.start();
}
void Form1::showTime()
{
QTime newtime = QTime();
newtime.setHMS(0,0,0,0);
i=i+1;
newtime=time.addSecs(i);
QString text = newtime.toString("hh:mm:ss");
ui->lcdNumber->display(text);
}
void Form1::stopTime()
{
timer.stop();
}
To copy to clipboard, switch view to plain text mode
timer is not working.timer is not starting
Bookmarks