From 15ccc7e499ac8dd1f75dfa75346d15c4b4d06324 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 25 Aug 2022 20:05:21 -0300 Subject: QVariant/Doc: document that you must register types before op>> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit But not before ::fromValue, since that registers automatically. Take the opportunity to add the \relates to the two streaming operators to QDataStream, so the documentation shows up *somewhere* at all. Pick-to: 6.4 Task-number: QTBUG-105469 Change-Id: Ic6547f8247454b47baa8fffd170eb8ffc31feb5d Reviewed-by: MÃ¥rten Nordheim --- src/corelib/kernel/qvariant.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/corelib/kernel/qvariant.cpp') diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 8f413b52e0..19fb33b675 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -1328,9 +1328,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 + it would print the following: + + \quotation + QVariant::load: unknown user type with name QList + \endquotation + \sa{Serializing Qt Data Types}{Format of the QDataStream operators} */ QDataStream &operator>>(QDataStream &s, QVariant &p) @@ -1341,6 +1353,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} */ @@ -2611,9 +2624,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() */ -- cgit v1.2.3