setTimeSpec() doesn't do the conversion, it only tells Qt that the date is in UTC. You also need to call toLocalTime(), toUTC() or toTimeSpec().
d.setTimeSpec( Qt::UTC );
qDebug() << d << d.toLocalTime();
QDateTime d( QDate( 2008, 6, 5 ), QTime( 12, 0 ) );
d.setTimeSpec( Qt::UTC );
qDebug() << d << d.toLocalTime();
To copy to clipboard, switch view to plain text mode
or
qDebug() << d << d.toLocalTime();
QDateTime d( QDate( 2008, 6, 5 ), QTime( 12, 0 ), QT::UTC );
qDebug() << d << d.toLocalTime();
To copy to clipboard, switch view to plain text mode
Bookmarks