diff -r 56cd8111b7f7 -r 41300fa6a67c src/corelib/kernel/qvariant.h --- a/src/corelib/kernel/qvariant.h Tue Jan 26 12:42:25 2010 +0200 +++ b/src/corelib/kernel/qvariant.h Tue Feb 02 00:43:10 2010 +0200 @@ -456,10 +456,11 @@ inline void qVariantSetValue(QVariant &v, const T &t) { //if possible we reuse the current QVariant private - const int type = qMetaTypeId(reinterpret_cast(0)); + const uint type = qMetaTypeId(reinterpret_cast(0)); QVariant::Private &d = v.data_ptr(); - if (v.isDetached() && (type <= int(QVariant::Char) || type == d.type)) { + if (v.isDetached() && (type == d.type || (type <= uint(QVariant::Char) && d.type <= uint(QVariant::Char)))) { d.type = type; + d.is_null = false; T *old = reinterpret_cast(d.is_shared ? d.data.shared->ptr : &d.data.ptr); if (QTypeInfo::isComplex) old->~T(); @@ -469,6 +470,13 @@ } } +template <> +inline void qVariantSetValue(QVariant &v, const QVariant &t) +{ + v = t; +} + + inline QVariant::QVariant() {} inline bool QVariant::isValid() const { return d.type != Invalid; } @@ -558,9 +566,7 @@ #endif #ifndef QT_MOC -#if !defined qdoc && defined Q_CC_MSVC && _MSC_VER < 1300 - -template T qvariant_cast(const QVariant &v, T * = 0) +template inline T qvariant_cast(const QVariant &v) { const int vid = qMetaTypeId(static_cast(0)); if (vid == v.userType()) @@ -573,28 +579,12 @@ return T(); } -template -inline T qVariantValue(const QVariant &variant, T *t = 0) -{ return qvariant_cast(variant, t); } - -template -inline bool qVariantCanConvert(const QVariant &variant, T *t = 0) +template<> inline QVariant qvariant_cast(const QVariant &v) { - return variant.canConvert(static_cast(qMetaTypeId(t))); -} -#else - -template T qvariant_cast(const QVariant &v) -{ - const int vid = qMetaTypeId(static_cast(0)); + static const int vid = qRegisterMetaType("QVariant"); if (vid == v.userType()) - return *reinterpret_cast(v.constData()); - if (vid < int(QMetaType::User)) { - T t; - if (qvariant_cast_helper(v, QVariant::Type(vid), &t)) - return t; - } - return T(); + return *reinterpret_cast(v.constData()); + return v; } template @@ -608,7 +598,6 @@ qMetaTypeId(static_cast(0)))); } #endif -#endif Q_DECLARE_SHARED(QVariant) Q_DECLARE_TYPEINFO(QVariant, Q_MOVABLE_TYPE);