diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2016-09-29 16:19:28 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com> | 2016-10-05 18:45:04 +0000 |
commit | fd7e00aff50c9ced966004238b2f74672dbbe300 (patch) | |
tree | c52d22d48f8e242bb8edc7a4a4ccb409ba9b64f6 /src/corelib/io/qsettings_mac.cpp | |
parent | 764f5bf48cc87f4c72550b853ab93b815454cd48 (diff) |
Don't truncate QDateTime milliseconds when storing QSettings on Apple platforms
The fix is trivial, but the patch adds a new QSettings tests that iterates most
of the QMetaTypes and verifies that storing and retrieving them again gives the
same value. This is a more complete test than the testVariantTypes tests, which
is limited to a subset of the QVariant types. The new tests borrows logic from
the QMetaType test machinery.
QSettings has been Q_ENUM'ified in the process, for improved debug output.
Note that on backends such as the INI backend, the metatype of the QVariant read
from the settings will be a string, so it won't match the input QVariant type,
but the result of converting that to the original value type should still work.
Task-number: QTBUG-56124
Change-Id: Ib03a26abf77c9fb449b94160d28bc4baeb095f25
Reviewed-by: Jake Petroules <jake.petroules@qt.io>
Diffstat (limited to 'src/corelib/io/qsettings_mac.cpp')
-rw-r--r-- | src/corelib/io/qsettings_mac.cpp | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/src/corelib/io/qsettings_mac.cpp b/src/corelib/io/qsettings_mac.cpp index 77f185d735..7d4f527ac5 100644 --- a/src/corelib/io/qsettings_mac.cpp +++ b/src/corelib/io/qsettings_mac.cpp @@ -175,17 +175,12 @@ static QCFType<CFPropertyListRef> macValue(const QVariant &value) break; case QVariant::DateTime: { - /* - CFDate, unlike QDateTime, doesn't store timezone information. - */ - QDateTime dt = value.toDateTime(); - if (dt.timeSpec() == Qt::LocalTime) { - QDateTime reference; - reference.setSecsSinceEpoch(qint64(kCFAbsoluteTimeIntervalSince1970)); - result = CFDateCreate(kCFAllocatorDefault, CFAbsoluteTime(reference.secsTo(dt))); - } else { + QDateTime dateTime = value.toDateTime(); + // CFDate, unlike QDateTime, doesn't store timezone information + if (dateTime.timeSpec() == Qt::LocalTime) + result = dateTime.toCFDate(); + else goto string_case; - } } break; case QVariant::Bool: @@ -303,9 +298,7 @@ static QVariant qtValue(CFPropertyListRef cfvalue) } return map; } else if (typeId == CFDateGetTypeID()) { - QDateTime dt; - dt.setSecsSinceEpoch(qint64(kCFAbsoluteTimeIntervalSince1970)); - return dt.addSecs((int)CFDateGetAbsoluteTime(static_cast<CFDateRef>(cfvalue))); + return QDateTime::fromCFDate(static_cast<CFDateRef>(cfvalue)); } return QVariant(); } |