summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qvariant.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/kernel/qvariant.cpp')
-rw-r--r--src/corelib/kernel/qvariant.cpp39
1 files changed, 22 insertions, 17 deletions
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp
index 10b86bcb48..7ccc5e500e 100644
--- a/src/corelib/kernel/qvariant.cpp
+++ b/src/corelib/kernel/qvariant.cpp
@@ -87,7 +87,7 @@ class HandlersManager
{
static const QVariant::Handler *Handlers[QModulesPrivate::ModulesCount];
public:
- const QVariant::Handler *operator[] (const int typeId) const
+ const QVariant::Handler *operator[] (const uint typeId) const
{
return Handlers[QModulesPrivate::moduleForType(typeId)];
}
@@ -776,6 +776,7 @@ static void customConstruct(QVariant::Private *d, const void *copy)
const QMetaType type(d->type);
const uint size = type.sizeOf();
if (!size) {
+ qWarning("Trying to construct an instance of an invalid type, type id: %i", d->type);
d->type = QVariant::Invalid;
return;
}
@@ -839,6 +840,9 @@ static void customStreamDebug(QDebug dbg, const QVariant &variant) {
QMetaType::TypeFlags flags = QMetaType::typeFlags(variant.userType());
if (flags & QMetaType::PointerToQObject)
dbg.nospace() << variant.value<QObject*>();
+#else
+ Q_UNUSED(dbg);
+ Q_UNUSED(variant);
#endif
}
#endif
@@ -909,7 +913,7 @@ Q_CORE_EXPORT void QVariantPrivate::registerHandler(const int /* Modules::Names
Here is some example code to demonstrate the use of QVariant:
- \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 0
+ \snippet code/src_corelib_kernel_qvariant.cpp 0
You can even store QList<QVariant> and QMap<QString, QVariant>
values in a variant, so you can easily construct arbitrarily
@@ -921,7 +925,7 @@ Q_CORE_EXPORT void QVariantPrivate::registerHandler(const int /* Modules::Names
have a defined type with no value set. However, note that QVariant
types can only be cast when they have had a value set.
- \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 1
+ \snippet code/src_corelib_kernel_qvariant.cpp 1
QVariant can be extended to support other types than those
mentioned in the \l Type enum. See the \l QMetaType documentation
@@ -935,13 +939,13 @@ Q_CORE_EXPORT void QVariantPrivate::registerHandler(const int /* Modules::Names
toColor() function. Instead, you can use the QVariant::value() or
the qvariant_cast() template function. For example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 2
+ \snippet code/src_corelib_kernel_qvariant.cpp 2
The inverse conversion (e.g., from QColor to QVariant) is
automatic for all data types supported by QVariant, including
GUI-related types:
- \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 3
+ \snippet code/src_corelib_kernel_qvariant.cpp 3
\section1 Using canConvert() and convert() Consecutively
@@ -1677,13 +1681,15 @@ void QVariant::load(QDataStream &s)
return;
}
}
- create(static_cast<int>(typeId), 0);
+ create(typeId, 0);
d.is_null = is_null;
if (!isValid()) {
+ if (s.version() < QDataStream::Qt_5_0) {
// Since we wrote something, we should read something
- QString x;
- s >> x;
+ QString x;
+ s >> x;
+ }
d.is_null = true;
return;
}
@@ -1745,7 +1751,8 @@ void QVariant::save(QDataStream &s) const
}
if (!isValid()) {
- s << QString();
+ if (s.version() < QDataStream::Qt_5_0)
+ s << QString();
return;
}
@@ -2172,7 +2179,6 @@ inline T qNumVariantToHelper(const QVariant::Private &d,
\b{Warning:} If the value is convertible to a \l LongLong but is too
large to be represented in an int, the resulting arithmetic overflow will
not be reflected in \a ok. A simple workaround is to use QString::toInt().
- Fixing this bug has been postponed to Qt 5 in order to avoid breaking existing code.
\sa canConvert(), convert()
*/
@@ -2192,7 +2198,6 @@ int QVariant::toInt(bool *ok) const
\b{Warning:} If the value is convertible to a \l ULongLong but is too
large to be represented in an unsigned int, the resulting arithmetic overflow will
not be reflected in \a ok. A simple workaround is to use QString::toUInt().
- Fixing this bug has been postponed to Qt 5 in order to avoid breaking existing code.
\sa canConvert(), convert()
*/
@@ -2527,7 +2532,7 @@ bool QVariant::convert(int targetTypeId)
}
/*!
- \fn convert(const int type, void *ptr) const
+ \fn bool QVariant::convert(const int type, void *ptr) const
\internal
Created for qvariant_cast() usage
*/
@@ -2671,7 +2676,7 @@ QDebug operator<<(QDebug dbg, const QVariant::Type p)
Example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 4
+ \snippet code/src_corelib_kernel_qvariant.cpp 4
\sa value(), fromValue(), canConvert()
*/
@@ -2688,7 +2693,7 @@ QDebug operator<<(QDebug dbg, const QVariant::Type p)
Example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 5
+ \snippet code/src_corelib_kernel_qvariant.cpp 5
\sa setValue(), fromValue(), canConvert()
*/
@@ -2700,7 +2705,7 @@ QDebug operator<<(QDebug dbg, const QVariant::Type p)
Example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 6
+ \snippet code/src_corelib_kernel_qvariant.cpp 6
\sa convert()
*/
@@ -2712,7 +2717,7 @@ QDebug operator<<(QDebug dbg, const QVariant::Type p)
Example:
- \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 7
+ \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.
@@ -2737,7 +2742,7 @@ QDebug operator<<(QDebug dbg, const QVariant::Type p)
For example, a QObject pointer can be stored in a variant with the
following code:
- \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 8
+ \snippet code/src_corelib_kernel_qvariant.cpp 8
\sa QVariant::fromValue()
*/