diff options
Diffstat (limited to 'src/corelib/kernel/qvariant.cpp')
-rw-r--r-- | src/corelib/kernel/qvariant.cpp | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 94d062f633..922def97d6 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -1069,7 +1069,7 @@ void QVariant::clear() /*! \fn QVariant::Type QVariant::nameToType(const char *name) - \deprecated [6.0] Use \c QMetaType.fromName(name).id() instead + \deprecated [6.0] Use \c QMetaType::fromName(name).id() instead Converts the string representation of the storage type given in \a name, to its enum representation. @@ -1312,9 +1312,21 @@ void QVariant::save(QDataStream &s) const /*! \since 4.4 + \relates QVariant Reads a variant \a p from the stream \a s. + \note If the stream contains types that aren't the built-in ones (see \l + QMetaType::Type), those types must be registered using qRegisterMetaType() + or QMetaType::registerType() before the variant can be properly loaded. If + an unregistered type is found, QVariant will set the corrupt flag in the + stream, stop processing and print a warning. For example, for QList<int> + it would print the following: + + \quotation + QVariant::load: unknown user type with name QList<int> + \endquotation + \sa{Serializing Qt Data Types}{Format of the QDataStream operators} */ QDataStream &operator>>(QDataStream &s, QVariant &p) @@ -1325,6 +1337,7 @@ QDataStream &operator>>(QDataStream &s, QVariant &p) /*! Writes a variant \a p to the stream \a s. + \relates QVariant \sa{Serializing Qt Data Types}{Format of the QDataStream operators} */ @@ -1390,8 +1403,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() */ @@ -1941,9 +1959,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() */ @@ -2595,9 +2617,6 @@ QT_WARNING_POP \snippet code/src_corelib_kernel_qvariant.cpp 7 - \note If you are working with custom types, you should use - the Q_DECLARE_METATYPE() macro to register your custom type. - \sa setValue(), value() */ |