summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2016-09-29 16:19:28 +0200
committerTor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>2016-10-05 18:45:04 +0000
commitfd7e00aff50c9ced966004238b2f74672dbbe300 (patch)
treec52d22d48f8e242bb8edc7a4a4ccb409ba9b64f6 /src
parent764f5bf48cc87f4c72550b853ab93b815454cd48 (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')
-rw-r--r--src/corelib/io/qsettings.h9
-rw-r--r--src/corelib/io/qsettings_mac.cpp19
2 files changed, 15 insertions, 13 deletions
diff --git a/src/corelib/io/qsettings.h b/src/corelib/io/qsettings.h
index 21fb9519de..edd59026ed 100644
--- a/src/corelib/io/qsettings.h
+++ b/src/corelib/io/qsettings.h
@@ -80,6 +80,9 @@ public:
AccessError,
FormatError
};
+#ifndef QT_NO_QOBJECT
+ Q_ENUM(Status)
+#endif
enum Format {
NativeFormat,
@@ -108,11 +111,17 @@ public:
CustomFormat15,
CustomFormat16
};
+#ifndef QT_NO_QOBJECT
+ Q_ENUM(Format)
+#endif
enum Scope {
UserScope,
SystemScope
};
+#ifndef QT_NO_QOBJECT
+ Q_ENUM(Scope)
+#endif
#ifndef QT_NO_QOBJECT
explicit QSettings(const QString &organization,
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();
}