qttimer.h
#ifndef QTTIMER_H #define QTTIMER_H #include <QtWidgets/QDialog> #include "ui_qttimer.h" class qttimer : public QDialog { Q_OBJECT public: qttimer(QWidget *parent = 0); ~qttimer(); private: Ui::qttimerClass ui; int count; private slots: void slottimedown(); }; #endif // QTTIMER_H
#include "qttimer.h" #include <QtCore/QTime> #include <QtCore/QTimer> #include <QtWidgets/QLabel> #include <QDateTime> qttimer::qttimer(QWidget *parent) : count(0) , QDialog(parent) { ui.setupUi(this); QTimer *time_clock = new QTimer(this); connect(time_clock, SIGNAL(timeout()), this, SLOT(slottimedown())); time_clock->start(1000); } qttimer::~qttimer() { } void qttimer::slottimedown() { QString value; ui.timelabel->setText(value.setNum(count++)); QDateTime time = QDateTime::currentDateTime(); QString str = time.toString("yyyy-MM-dd dddd hh:mm:ss"); ui.datelabel->setText(str); }