check.h
#ifndef CHECK_H
#define CHECK_H
#include<QWidget>
class QPushButton;
class QLabel;
class QTime;
class check : public QWidget{
Q_OBJECT
private:
QLabel *work;
QLabel *walk;
QPushButton *workbutton;
QPushButton *walkbutton;
QPushButton* newday;
QTime *worktime;
QTime *walktime;
QTime *temptimer;
bool flagWW; //вышел/вернулся
bool flagND; //флаг новый день?
public:
check(QWidget* pwgt=0);
private slots:
void check_slot();
};
#endif // CHECK_H
check.cpp
#include <QtGui>
#include"check.h"
check::check(QWidget *pwgt):QWidget(pwgt)
{
flagWW=0;
flagND=0;
work=new QLabel();
walk=new QLabel();
workbutton=new QPushButton("work");
walkbutton=new QPushButton("walk");
newday=new QPushButton("newday");
connect(workbutton,SIGNAL(clicked()),SLOT(check_slot()));
connect(walkbutton,SIGNAL(clicked()),SLOT(check_slot()));
connect(newday,SIGNAL(clicked()),SLOT(check_slot()));
worktime=new QTime(00,00,00);
walktime=new QTime(00,00,00);
temptimer=new QTime(00,00,00);
temptimer->start(); // запускаем отсчёт
work->setText(worktime->toString());
walk->setText(walktime->toString());
QBoxLayout* LabelLayout = new QBoxLayout(QBoxLayout::LeftToRight);
QBoxLayout* ButtonLayout = new QBoxLayout(QBoxLayout::LeftToRight);
QBoxLayout* MainLayout = new QBoxLayout(QBoxLayout::TopToBottom);
LabelLayout->addWidget(work);
LabelLayout->addWidget(walk);
ButtonLayout->addWidget(workbutton);
ButtonLayout->addWidget(walkbutton);
MainLayout->addWidget(newday);
MainLayout->addLayout(LabelLayout);
MainLayout->addLayout(ButtonLayout);
setLayout(MainLayout);
}
void check::check_slot()
{
worktime->addMSecs(temptimer->elapsed()); // загвоздка здесь милисекунды не добавляются
work->setText(worktime->toString("hh:mm:ss.zzz"));
temptimer->restart();
}
main.cpp
#include <QApplication>
#include"check.h"
int main (int argc,char** argv)
{
QApplication app(argc,argv);
check checkman;
checkman.show();
return app.exec();
}
Что делаю не так? помогите пожалуйста.