On 03/28/2011 05:08 PM, ext Harri Pasanen wrote:
> Hi,
>
> I'm a bit confused. Can anyone explain why this code
>
> QGeoPositionInfo pos = _posSource->lastKnownPosition();
> if (pos.coordinate().isValid()) { // if we a valid position
> QDateTime now = QDateTime::currentDateTime();
> qDebug()<< "Now is:"<< now;
> now = now.toUTC();
> qDebug()<< "Now is UTC:"<< now;
> qDebug()<< "Position says it is (UTC):"<< pos.timestamp();
> qDebug()<< "which makes it "<< pos.timestamp().secsTo(now)<< "
> seconds old";
>
> gives this output:
>
> Now is: QDateTime("Mon Mar 28 08:58:17 2011")
> Now is UTC: QDateTime("Mon Mar 28 06:58:17 2011")
> Position says it is (UTC): QDateTime("Mon Mar 28 06:50:00 2011")
> which makes it 7697 seconds old
>
>
> I would have expected 8 m 17 s difference, 497 seconds.
>
> As if toSecs() would not know that "now" has been converted to UTC?
Hi,
This is the result of a bug that has been fixed in subsequent version of
Qt Mobility.
The timestamp reported by the position is a UTC time but the QDateTime
holding the timestamp was not set up to be aware of this.
QDateTime::secsTo(...) converts both times to UTC before doing the
comparison. Since the position timestamp wasn't marked as being UTC it
has 2 hours subtracted from it before the comparison in order to convert
it to UTC, and that's where the additional 7200 seconds come from.
A work around for Qt Mobility 1.0.2 would be to do
QDateTime timestamp = pos.timestamp();
timestamp.setTimeSpec(Qt::UTC);
Sorry for the inconvenience,
Cheers,
Dave
_______________________________________________
Qt-mobility-feedback mailing list
[email protected]
http://lists.qt.nokia.com/mailman/listinfo/qt-mobility-feedback