timeInput = QTime::currentTime();WorkTime = new QTimer(this);connect(WorkTime,SIGNAL(timeout()),this,SLOT(SetWorkTime()));WorkTime->start(1000);
void MainWindow::SetWorkTime(){ QTime curenttime = QTime::currentTime(); QTime t; int hours = curenttime.hour() - timeInput.hour(); int minuts = curenttime.minute() - timeInput.minute(); int seconds =curenttime.second() - timeInput.second(); t.setHMS(hours,minuts,seconds); ui->labelWorkTime->setText(t.toString());}
C++ (Qt)int QDateTime::secsTo ( const QDateTime & other ) constint QTime ::secsTo ( const QTime & t ) const
timeInput = new QTime;timeInput->start();timeInput->setHMS(0,0,0);WorkTime = new QTimer(this);connect(WorkTime,SIGNAL(timeout()),this,SLOT(SetWorkTime()));
timeInput->addSecs(1);ui->labelWorkTime->setText(timeInput->toString());