diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2022-10-06 09:01:15 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2022-10-11 09:36:11 -0700 |
commit | 49e62c51f275c94501a3c42b8fbd8f11b87e9d41 (patch) | |
tree | f826ea37cf0ee52c094960f4ce2a124624a1815d /src/corelib/kernel/qvariant.cpp | |
parent | 909112fa522a188373741797402445d22e3974b8 (diff) |
QVariant/Doc: expand what toList & toMap conversions may succeed
I don't know when conversion through sequential and associative
iteratables was added, probably some time in the 5.x. QString and
QByteArray got conversions to sequential iteratables for Qt 6.1 with
commit c9a11022692f9a4bd36beb0cd001686694a48915. Since that was
intentional, I'm just documenting reality.
Fixes: QTBUG-107246
Pick-to: 6.2 6.3 6.4
Change-Id: Id8d5e3999fe94b03acc1fffd171b863b1a0ead68
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/corelib/kernel/qvariant.cpp')
-rw-r--r-- | src/corelib/kernel/qvariant.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 19fb33b675..5e949487db 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -1419,8 +1419,13 @@ QString QVariant::toString() const } /*! - Returns the variant as a QMap<QString, QVariant> if the variant - has type() \l QMetaType::QVariantMap; otherwise returns an empty map. + Returns the variant as a QVariantMap if the variant has type() \l + QMetaType::QVariantMap. If it doesn't, QVariant will attempt to + convert the type to a map and then return it. This will succeed for + any type that has registered a converter to QVariantMap or which was + declared as a associative container using + \l{Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE}. If none of those + conditions are true, this function will return an empty map. \sa canConvert(), convert() */ @@ -1970,9 +1975,13 @@ qreal QVariant::toReal(bool *ok) const } /*! - Returns the variant as a QVariantList if the variant has userType() - \l QMetaType::QVariantList or \l QMetaType::QStringList; otherwise returns - an empty list. + Returns the variant as a QVariantList if the variant has userType() \l + QMetaType::QVariantList. If it doesn't, QVariant will attempt to convert + the type to a list and then return it. This will succeed for any type that + has registered a converter to QVariantList or which was declared as a + sequential container using \l{Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE}. If + none of those conditions are true, this function will return an empty + list. \sa canConvert(), convert() */ |