diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-10-28 14:55:47 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-10-28 15:07:36 (GMT) |
commit | 51f1d68addd23516d7e6e252e476feac0a95d0c0 (patch) | |
tree | 07d0e3fbb6f30d66eb4127253867e48b87c3aa8a /src/corelib/kernel | |
parent | d560894ad085ac8c6266fd1af66139db950f473f (diff) | |
download | Qt-51f1d68addd23516d7e6e252e476feac0a95d0c0.zip Qt-51f1d68addd23516d7e6e252e476feac0a95d0c0.tar.gz Qt-51f1d68addd23516d7e6e252e476feac0a95d0c0.tar.bz2 |
Fix warning in qvariant.h header + make sure QVariant in QVariant works as expected
Also add more test
Reviewed-by: Thierry
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r-- | src/corelib/kernel/qvariant.h | 39 |
1 files changed, 12 insertions, 27 deletions
diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index 4cce529..a1ab4e9 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -456,9 +456,9 @@ template <typename T> inline void qVariantSetValue(QVariant &v, const T &t) { //if possible we reuse the current QVariant private - const int type = qMetaTypeId<T>(reinterpret_cast<T *>(0)); + const uint type = qMetaTypeId<T>(reinterpret_cast<T *>(0)); QVariant::Private &d = v.data_ptr(); - if (v.isDetached() && (type <= int(QVariant::Char) || type == d.type)) { + if (v.isDetached() && (type <= uint(QVariant::Char) || type == d.type)) { d.type = type; d.is_null = false; T *old = reinterpret_cast<T*>(d.is_shared ? d.data.shared->ptr : &d.data.ptr); @@ -470,6 +470,13 @@ inline void qVariantSetValue(QVariant &v, const T &t) } } +template <> +inline void qVariantSetValue<QVariant>(QVariant &v, const QVariant &t) +{ + v = t; +} + + inline QVariant::QVariant() {} inline bool QVariant::isValid() const { return d.type != Invalid; } @@ -559,9 +566,7 @@ inline bool operator!=(const QVariant &v1, const QVariantComparisonHelper &v2) #endif #ifndef QT_MOC -#if !defined qdoc && defined Q_CC_MSVC && _MSC_VER < 1300 - -template<typename T> T qvariant_cast(const QVariant &v, T * = 0) +template<typename T> inline T qvariant_cast(const QVariant &v) { const int vid = qMetaTypeId<T>(static_cast<T *>(0)); if (vid == v.userType()) @@ -574,28 +579,9 @@ template<typename T> T qvariant_cast(const QVariant &v, T * = 0) return T(); } -template<typename T> -inline T qVariantValue(const QVariant &variant, T *t = 0) -{ return qvariant_cast<T>(variant, t); } - -template<typename T> -inline bool qVariantCanConvert(const QVariant &variant, T *t = 0) +template<> inline QVariant qvariant_cast<QVariant>(const QVariant &v) { - return variant.canConvert(static_cast<QVariant::Type>(qMetaTypeId<T>(t))); -} -#else - -template<typename T> T qvariant_cast(const QVariant &v) -{ - const int vid = qMetaTypeId<T>(static_cast<T *>(0)); - if (vid == v.userType()) - return *reinterpret_cast<const T *>(v.constData()); - if (vid < int(QMetaType::User)) { - T t; - if (qvariant_cast_helper(v, QVariant::Type(vid), &t)) - return t; - } - return T(); + return v; } template<typename T> @@ -609,7 +595,6 @@ inline bool qVariantCanConvert(const QVariant &variant) qMetaTypeId<T>(static_cast<T *>(0)))); } #endif -#endif Q_DECLARE_SHARED(QVariant) Q_DECLARE_TYPEINFO(QVariant, Q_MOVABLE_TYPE); |