summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
diff options
context:
space:
mode:
authorStephen Kelly <stephen.kelly@kdab.com>2012-06-09 22:57:35 +0200
committerQt by Nokia <qt-info@nokia.com>2012-06-20 15:45:07 +0200
commit668efc29fd85bbae2395a4eca8d0ad71ad6ee3d1 (patch)
treeffccf50b396428156cafb3c6a51ddb87d2359f28 /tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
parent534bcc96676ac02fc327f9e43d3785c7424b0750 (diff)
Add some internal API for extracting a QSharedPointer<T> from QVariant.
The T must be derived from QObject, or it will fail to compile. This will allow scripting or other 'wrapping' and runtime environments like QtDeclarative to handle QSharedPointers to types derived from QObject properly. A QSharedPointer<T> can be inserted into a QVariant, and where T derives from QObject, a QSharedPointer<QObject> can be extracted from the QVariant, and its properties are then accessible. Change-Id: I68d6d89aceceb019267bd7301baa2047f9c09b90 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp')
-rw-r--r--tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp b/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
index 3540df17ac..fd20a1cf5d 100644
--- a/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
+++ b/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
@@ -63,6 +63,8 @@ private slots:
void disconnect();
void castDuringDestruction();
void threadSafety();
+
+ void qvariantCast();
};
void tst_QPointer::constructors()
@@ -348,6 +350,41 @@ void tst_QPointer::threadSafety()
owner.wait();
}
+void tst_QPointer::qvariantCast()
+{
+ QPointer<QFile> tracking = new QFile;
+ tracking->setObjectName("A test name");
+ QVariant v = QVariant::fromValue(tracking);
+
+ {
+ QPointer<QObject> other = qPointerFromVariant<QObject>(v);
+ QCOMPARE(other->objectName(), QString::fromLatin1("A test name"));
+ }
+ {
+ QPointer<QIODevice> other = qPointerFromVariant<QIODevice>(v);
+ QCOMPARE(other->objectName(), QString::fromLatin1("A test name"));
+ }
+ {
+ QPointer<QFile> other = qPointerFromVariant<QFile>(v);
+ QCOMPARE(other->objectName(), QString::fromLatin1("A test name"));
+ }
+ {
+ QPointer<QThread> other = qPointerFromVariant<QThread>(v);
+ QVERIFY(!other);
+ }
+ {
+ QPointer<QFile> toBeDeleted = new QFile;
+ QVariant deletedVariant = QVariant::fromValue(toBeDeleted);
+ delete toBeDeleted;
+ QPointer<QObject> deleted = qPointerFromVariant<QObject>(deletedVariant);
+ QVERIFY(!deleted);
+ }
+
+ // Intentionally does not compile.
+// QPointer<int> sop = qPointerFromVariant<int>(v);
+}
+
+
QTEST_MAIN(tst_QPointer)
#include "tst_qpointer.moc"