From 49e62c51f275c94501a3c42b8fbd8f11b87e9d41 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 6 Oct 2022 09:01:15 -0700 Subject: 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 --- src/corelib/kernel/qvariant.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/corelib/kernel') 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 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() */ -- cgit v1.2.3