diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-10-19 10:07:29 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-10-19 22:11:50 +0200 |
commit | 37c7ef4f4a8478e94eaf0af5b40c279c476fa561 (patch) | |
tree | 76cdeea2afb6785eeea0651054bd5787d9541810 /src/corelib/kernel/qsequentialiterable.cpp | |
parent | 52083e4da505bfe6abeb9e36ffd68ecefbbf6964 (diff) |
QMetaContainer: Consistently coerce types
The high-level iterable interfaces should coerce the types of most
QVariants passed to the expected ones. To do this, move the type
coercion code into qvariant.{h|cpp} so that it is available to the
QVariantRef specializations.
The exception are variants passed to the find() functions of associative
iterables. Here, we should not coerce values we cannot convert to the
default-constructed keys. Instead we return end() in such cases.
Fixes: QTBUG-87687
Change-Id: I0bd4e5c4e4e270dd3bf36cb3fb115794828077f2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/kernel/qsequentialiterable.cpp')
-rw-r--r-- | src/corelib/kernel/qsequentialiterable.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/corelib/kernel/qsequentialiterable.cpp b/src/corelib/kernel/qsequentialiterable.cpp index 6ce41a1edf..054d97d90f 100644 --- a/src/corelib/kernel/qsequentialiterable.cpp +++ b/src/corelib/kernel/qsequentialiterable.cpp @@ -106,8 +106,8 @@ QT_BEGIN_NAMESPACE */ void QSequentialIterable::addValue(const QVariant &value, Position position) { - QVariant converted = value; - const void *valuePtr = QIterablePrivate::coerceType(converted, metaContainer().valueMetaType()); + QtPrivate::QVariantTypeCoercer coercer; + const void *valuePtr = coercer.coerce(value, metaContainer().valueMetaType()); switch (position) { case AtBegin: @@ -181,8 +181,8 @@ QVariant QSequentialIterable::at(qsizetype idx) const */ void QSequentialIterable::set(qsizetype idx, const QVariant &value) { - QVariant converted = value; - const void *dataPtr = QIterablePrivate::coerceType(converted, metaContainer().valueMetaType()); + QtPrivate::QVariantTypeCoercer coercer; + const void *dataPtr = coercer.coerce(value, metaContainer().valueMetaType()); const QMetaSequence meta = metaContainer(); if (meta.canSetValueAtIndex()) { |