summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2016-05-16 14:22:03 +0200
committerOlivier Goffart (Woboq GmbH) <ogoffart@woboq.com>2016-05-16 15:58:28 +0000
commit45eba73492c89157b8c353548a948d538748cd43 (patch)
tree1a9fc5e39280212d149b9ba84c6d61e98acda150 /src/corelib
parent474af0a61d6154006966a775d186687aa8881708 (diff)
Fix QVariant conversion to an enum type.
QVariant::canConvert<Enum> was returning true for everything can can be converted to integer, but not for integer itself. That's because in QVariant::canConvert we set the targetType to Int of it's an enum, but the Int->Int case was not on the conversion matrix. So this commits adds it to the conversion matrix and now QVariant::canConvert<Enum> returns consistently true for int itself. But even tough canConvert returned true, it did not actualy do any conversion to the enum type itself. Fix that by handling the case properlt in 'convert' [ChangeLog][QtCore][QVariant] Fixed QVariant::canConvert and conversion from integer types to enumeration types. Task-number: QTBUG-53384 Change-Id: I6ac066f3900e31bfcea7af77836ddfc7730bd60b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/kernel/qvariant.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp
index 9298093f44..7596699843 100644
--- a/src/corelib/kernel/qvariant.cpp
+++ b/src/corelib/kernel/qvariant.cpp
@@ -945,6 +945,26 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
}
}
#endif
+ if (QMetaType::typeFlags(t) & QMetaType::IsEnumeration) {
+ qlonglong value = qConvertToNumber(d, ok);
+ if (*ok) {
+ switch (QMetaType::sizeOf(t)) {
+ case 1:
+ *static_cast<signed char *>(result) = value;
+ return true;
+ case 2:
+ *static_cast<qint16 *>(result) = value;
+ return true;
+ case 4:
+ *static_cast<qint32 *>(result) = value;
+ return true;
+ case 8:
+ *static_cast<qint64 *>(result) = value;
+ return true;
+ }
+ }
+ return *ok;
+ }
return false;
}
return true;
@@ -2819,7 +2839,7 @@ static const quint32 qCanConvertMatrix[QVariant::LastCoreType + 1] =
/*Int*/ 1 << QVariant::UInt | 1 << QVariant::String | 1 << QVariant::Double
| 1 << QVariant::Bool | 1 << QVariant::LongLong | 1 << QVariant::ULongLong
- | 1 << QVariant::Char | 1 << QVariant::ByteArray,
+ | 1 << QVariant::Char | 1 << QVariant::ByteArray | 1 << QVariant::Int,
/*UInt*/ 1 << QVariant::Int | 1 << QVariant::String | 1 << QVariant::Double
| 1 << QVariant::Bool | 1 << QVariant::LongLong | 1 << QVariant::ULongLong