From f44d2ea1cc14587ab8f0ba3a36f10ab3bee34504 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 13 Jul 2020 10:02:40 +0200 Subject: [PATCH] Always try to conversions through QMetaType Always ask QMetaType to convert first before trying the builtin code in QVariant. That way we can migrate conversions piece by piece to QMetaType. Change-Id: I4fd1bad3ef045d37f84f68e748a6357e0ee0c16c Reviewed-by: Thiago Macieira --- src/corelib/kernel/qvariant.cpp | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 80aefa0c4d..137c2bb783 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -2462,11 +2462,9 @@ inline T qVariantToHelper(const QVariant::Private &d) return d.get(); T ret; - if (d.typeId() >= QMetaType::LastCoreType || targetType.id() >= QMetaType::LastCoreType) { - const void * const from = d.storage(); - if (QMetaType::convert(from, d.typeId(), &ret, targetType.id())) - return ret; - } + const void * const from = d.storage(); + if (QMetaType::convert(from, d.typeId(), &ret, targetType.id())) + return ret; convert(&d, targetType.id(), &ret); return ret; @@ -2896,8 +2894,7 @@ inline T qNumVariantToHelper(const QVariant::Private &d, bool *ok, const T& val) return val; T ret = 0; - if ((d.typeId() >= QMetaType::LastCoreType || t >= QMetaType::LastCoreType) - && QMetaType::convert(d.storage(), d.typeId(), &ret, t)) + if (QMetaType::convert(d.storage(), d.typeId(), &ret, t)) return ret; bool success = convert(&d, t, &ret); @@ -3003,11 +3000,8 @@ bool QVariant::toBool() const bool res = false; - if (d.typeId() >= QMetaType::LastCoreType) { - const void * const from = constData(); - if (QMetaType::convert(from, d.typeId(), &res, QMetaType::Bool)) - return res; - } + if (QMetaType::convert(constData(), d.typeId(), &res, QMetaType::Bool)) + return res; ::convert(&d, Bool, &res); @@ -3547,10 +3541,7 @@ bool QVariant::convert(int targetTypeId) } bool isOk = false; - if (oldValue.d.typeId() >= QMetaType::LastCoreType || targetTypeId >= QMetaType::LastCoreType) { - const void * const from = oldValue.constData(); - isOk = QMetaType::convert(from, oldValue.d.typeId(), data(), targetTypeId); - } + isOk = QMetaType::convert(oldValue.constData(), oldValue.d.typeId(), data(), targetTypeId); if (!isOk) isOk = ::convert(&oldValue.d, targetTypeId, data()); @@ -3565,11 +3556,8 @@ bool QVariant::convert(int targetTypeId) */ bool QVariant::convert(const int type, void *ptr) const { - if (d.typeId() >= QMetaType::LastCoreType || type >= QMetaType::LastCoreType) { - const void * const from = constData(); - if (QMetaType::convert(from, d.typeId(), ptr, type)) - return true; - } + if (QMetaType::convert(constData(), d.typeId(), ptr, type)) + return true; return ::convert(&d, type, ptr); }