[Qt-interest] How calculate time span (days, hours, minutes) QDateTime difference?

Scott Aron Bloom Scott.Bloom at onshorecs.com
Sat Jun 12 05:53:27 CEST 2010


NP.. Glad to be of some help..

BTW on the notion of QTimeSpan...

Frankly I think it's a great little worker bee class..  Note, there are
plenty of times where I use QTime with a .start, and a elapsed... and it
fails on me, when it cross date time barriers, or goes longer than 24
hours...

So having a QTimeSpan that would have QTimeSpan
operator-(QDateTime,QDateTime) as well as the QTime, plus cool
formatting would be a great idea..

We have ALL done the work of this class, and yes we can ALL do it again,
but having a class provided for us, that simply makes that type of grunt
formatting of simple, but mistake prone code (forgetting to deal with
time zones, or if the second time is before the first etc etc etc) is a
great idea...

I bet if we coded it cleanly, followed .Net's api (which is pretty good
for this actually) we could get libQxt to add it.

Scott

-----Original Message-----
From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] On Behalf Of Dan White
Sent: Friday, June 11, 2010 8:39 PM
To: Qt-interest Interest
Subject: Re: [Qt-interest] How calculate time span (days, hours,minutes)
QDateTime difference?

Thanks for that clarification.

I just used qDebug for the quick-and-dirty demonstration.

Your counter-example is much more appropriate for production type  
code.  Very neat and complete.

On Jun 11, 2010, at 7:01 PM, Scott Aron Bloom wrote:

> You are getting the quotes because qDebug puts quotes around all  
> strings
> when it prints them out...
>
> If you did..
>
> QMessageBox::information( NULL, "Title",  tr( "Arrival:  
> %1<br>Departure:
> %2<br>Days: %3 When:%4" ).arg( arrival.toStrign() ).arg(
> departure.toString() )..... )
>
> It would display fine
>
> Scott
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest




More information about the Qt-interest-old mailing list