summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/kernel/qvariant.h2
-rw-r--r--tests/auto/qvariant/tst_qvariant.cpp17
2 files changed, 18 insertions, 1 deletions
diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h
index 6844d3e..e923844 100644
--- a/src/corelib/kernel/qvariant.h
+++ b/src/corelib/kernel/qvariant.h
@@ -448,7 +448,7 @@ 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));
QVariant::Private &d = v.data_ptr();
- if (type <= int(QVariant::Char) || (type == d.type && v.isDetached())) {
+ if (v.isDetached() && (type <= int(QVariant::Char) || type == d.type)) {
d.type = type;
T *old = reinterpret_cast<T*>(d.is_shared ? d.data.shared->ptr : &d.data.ptr);
if (QTypeInfo<T>::isComplex)
diff --git a/tests/auto/qvariant/tst_qvariant.cpp b/tests/auto/qvariant/tst_qvariant.cpp
index 0310276..63e47ab 100644
--- a/tests/auto/qvariant/tst_qvariant.cpp
+++ b/tests/auto/qvariant/tst_qvariant.cpp
@@ -255,6 +255,7 @@ private slots:
void convertByteArrayToBool() const;
void convertByteArrayToBool_data() const;
void toIntFromQString() const;
+ void task256984_setValue();
};
Q_DECLARE_METATYPE(QDate)
@@ -2967,5 +2968,21 @@ void tst_QVariant::toIntFromQString() const
QVERIFY(ok);
}
+void tst_QVariant::task256984_setValue()
+{
+ QTransform t; //we just take a value so that we're sure that it will be shared
+ QVariant v1 = t;
+ QVERIFY( v1.isDetached() );
+ QVariant v2 = v1;
+ QVERIFY( !v1.isDetached() );
+ QVERIFY( !v2.isDetached() );
+
+ qVariantSetValue(v2, 3); //set an integer value
+
+ QVERIFY( v1.isDetached() );
+ QVERIFY( v2.isDetached() );
+}
+
+
QTEST_MAIN(tst_QVariant)
#include "tst_qvariant.moc"