Witam serdecznie,
troszkę się namęczyłem ale wydaje mi się, że wszystko działa prawidłowo.
Do pliku.h dodaj biblioteki :
#include <QTime>
#include <cmath>
poźniej do sekcji private:
QTime czasa , czasb ;
QString a,b;
QString a1,a2,a3,b1,b2,b3,c1,c2,c3;
W pliku.cpp w konstruktorze wprowadź taki kod :
czasa = ui->timeEdit->time();
czasb = ui->timeEdit_2->time();
a = czasa.toString();
b = czasb.toString();
a1 = QString("%1%2").arg(a.at(0)).arg(a.at(1)) ;
a2 = QString("%1%2").arg(a.at(3)).arg(a.at(4)) ;
a3 = QString("%1%2").arg(a.at(6)).arg(a.at(7)) ;
b1 = QString("%1%2").arg(b.at(0)).arg(b.at(1)) ;
b2 = QString("%1%2").arg(b.at(3)).arg(b.at(4)) ;
b3 = QString("%1%2").arg(b.at(6)).arg(b.at(7)) ;
c1 = QString::number(abs(a1.toInt()-b1.toInt()));
if(((a1.toInt()-b1.toInt()) < 0) && ((a1.toInt()-b1.toInt()) > -10))
c1 = "0"+QString::number(abs(a1.toInt()-b1.toInt()));
else if(((a1.toInt()-b1.toInt()) < 10) && ((a1.toInt()-b1.toInt()) >= 0))
c1 = "0"+QString::number(abs(a1.toInt()-b1.toInt()));
c2 = QString::number(abs(a2.toInt()-b2.toInt()));
if(((a2.toInt()-b2.toInt()) < 0) && ((a2.toInt()-b2.toInt()) > -10) )
c2 = "0"+QString::number(abs(a2.toInt()-b2.toInt()));
else if(((a2.toInt()-b2.toInt()) < 10) && ((a2.toInt()-b2.toInt()) >= 0))
c2 = "0"+QString::number(abs(a2.toInt()-b2.toInt()));
c3 = QString::number(abs(a3.toInt()-b3.toInt()));
if(((a3.toInt()-b3.toInt()) < 0)&& ((a3.toInt()-b3.toInt()) > -10) )
c3 = "0"+QString::number(abs(a3.toInt()-b3.toInt()));
else if(((a3.toInt()-b3.toInt()) < 10) && ((a3.toInt()-b3.toInt()) >= 0))
c3 = "0"+QString::number(abs(a3.toInt()-b3.toInt()));
ui->label->setText(c1+":"+c2+":"+c3);
Ten program działa tak że pobiera czas z QTimeEdit(nazywa się timeEdit) następnie porównuje czas z innym czasem zapisanym w QTimeEdit(nazwya się timeEdit_2) a następnie wyświetla różnicę w etykiecie QLabel(nazywa się label).
Wydaje mi się, że istnieją jakieś specjalne metody do oblicznia różnic czasowych ja to zrobiłem troszkę łopatologicznie ale najważniejsze, że działa. Mam nadzieje, że pomogłem.