From b132648084df231c196e726c899761d83d0766cc Mon Sep 17 00:00:00 2001 From: David Faure Date: Fri, 26 Mar 2021 10:05:31 +0100 Subject: KConfig: preserve the milliseconds component of QDateTime I stored a file's lastModified() into KConfig, to compare with it again on next start, and the loss of milliseconds made the code think the timestamps didn't match, even when they did. --- src/core/kconfiggroup.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/core/kconfiggroup.cpp b/src/core/kconfiggroup.cpp index cc4f8d0c..14cbcab8 100644 --- a/src/core/kconfiggroup.cpp +++ b/src/core/kconfiggroup.cpp @@ -27,6 +27,7 @@ #include #include +#include class KConfigGroupPrivate : public QSharedData { @@ -325,14 +326,18 @@ QVariant KConfigGroup::convertToQVariant(const char *pKey, const QByteArray &val return size; } case QMetaType::QDateTime: { - const auto list = asIntList(value); - if (list.count() != 6) { + const auto list = asRealList(value); + if (list.count() < 6) { qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault) << formatError(6, list.count()); return aDefault; } const QDate date(list.at(0), list.at(1), list.at(2)); - const QTime time(list.at(3), list.at(4), list.at(5)); + const qreal totalSeconds = list.at(5); + qreal seconds; + const qreal fractional = modf(totalSeconds, &seconds); + const qreal milliseconds = round(fractional * 1000.0); + const QTime time(list.at(3), list.at(4), seconds, milliseconds); const QDateTime dt(date, time); if (!dt.isValid()) { qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault); @@ -1044,7 +1049,7 @@ void KConfigGroup::writeEntry(const char *key, const QVariant &value, time.hour(), time.minute(), - time.second(), + time.second() + time.msec()/1000.0, }; writeEntry(key, list, flags); -- cgit v1.2.1