summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/kernel/qvariant.cpp9
-rw-r--r--tests/auto/qvariant/tst_qvariant.cpp2
2 files changed, 7 insertions, 4 deletions
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp
index a91fb75..9adfa57 100644
--- a/src/corelib/kernel/qvariant.cpp
+++ b/src/corelib/kernel/qvariant.cpp
@@ -174,10 +174,13 @@ static void construct(QVariant::Private *x, const void *copy)
case QVariant::UserType:
break;
default:
- x->is_shared = true;
- x->data.shared = new QVariant::PrivateShared(QMetaType::construct(x->type, copy));
- if (!x->data.shared->ptr)
+ void *ptr = QMetaType::construct(x->type, copy);
+ if (!ptr) {
x->type = QVariant::Invalid;
+ } else {
+ x->is_shared = true;
+ x->data.shared = new QVariant::PrivateShared(ptr);
+ }
break;
}
x->is_null = !copy;
diff --git a/tests/auto/qvariant/tst_qvariant.cpp b/tests/auto/qvariant/tst_qvariant.cpp
index 1722ad3..5ed0dcd 100644
--- a/tests/auto/qvariant/tst_qvariant.cpp
+++ b/tests/auto/qvariant/tst_qvariant.cpp
@@ -2622,7 +2622,7 @@ void tst_QVariant::qvariant_cast_QObject_data() {
QTest::addColumn<QVariant>("data");
QTest::addColumn<bool>("success");
- QTest::newRow("from QObject") << QVariant(QMetaType::QObjectStar, new QObject) << true;
+ QTest::newRow("from QObject") << QVariant(QMetaType::QObjectStar, new QObject(this)) << true;
QTest::newRow("from String") << QVariant(QLatin1String("1, 2, 3")) << false;
QTest::newRow("from int") << QVariant((int) 123) << false;
}