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

Sean Harmer sean.harmer at maps-technology.com
Fri Jun 11 21:04:54 CEST 2010


Hi,

On Friday 11 June 2010 19:54:27 Reece Dunn wrote:
<snip />
> It would be great if there was an easier way to do this using Qt classes,
> e.g.:
> 
> 	if (!m_start_time.isValid())
> 	{
> 		m_start_time = QDateTime::now();
> 		m_start_progress = progress / 100.0f;
> 	}
> 	else
> 	{
> 		float current_progress = progress / 100.0f;
> 
> 		QTimeSpan elapsed_time = QDateTime::now() - m_start_time;
> 		QTimeSpan total_time = elapsed_time / (current_progress -
> m_start_progress); QTimeSpan played_time = total_time * current_progress;
> 
> 		m_progress->setText(i18nc("@info:status", "%1 of %2 (%3%)")
> 			.arg(played_time.format("%H:%M:%S"))
> 			.arg(total_time.format("%H:%M:%S"))
> 			.arg(progress, 5, 'f', 2, '0'));
> 	}

Yeah my use case is for handling time durations within a plotting library I am 
putting together based on QGraphicsView so I need a similar set of operators 
and functions on such a class.

Obviously being able to shove a QTimeSpan into a QVariant would be useful too.

Cheers,

Sean



More information about the Qt-interest-old mailing list