diff options
author | Stephen Kelly <stephen.kelly@kdab.com> | 2012-01-12 20:01:15 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-10 11:17:46 +0200 |
commit | 59ed8c355b99df0b949003a438ab850274261aa0 (patch) | |
tree | 7f019270e9e8457d385d94c6e8a9b1679b396fb2 /tests/auto/qml/qqmlcontext | |
parent | f20d726766bf5e875f96fc5ce8885afe5c3fae4a (diff) |
Make it possible to handle pointers to QObject derived in QML.
This way, properties of QObject derived types can be read in QML
code for example:
Q_PROPERTY(MyObject* obj READ obj CONSTANT)
Previously, only QObject* types could be read by QML:
Q_PROPERTY(QObject* obj READ obj CONSTANT)
This meant that multiple properties and methods had to be created
for classes which were relevant to both QML and non-QML code.
This patch lifts that restriction.
As a consequence, we can also remove a Q_EXPECT_FAIL from
the qqmllanguage unit test. That test was introduced in
commit 92562eacbc3c (Allow signal parameters which are custom QML
object-types, 2012-07-13) to document knowledge of the limitation
while fixing it as much as possible.
Task-number: QTBUG-26662
Change-Id: Ic85fa73c6f3655189438ec509765bae2eab9993a
Reviewed-by: Alan Alpert (Personal) <416365416c@gmail.com>
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'tests/auto/qml/qqmlcontext')
-rw-r--r-- | tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp b/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp index e0c20307a8..4f21231184 100644 --- a/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp +++ b/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp @@ -72,6 +72,7 @@ private slots: void qtbug_22535(); void evalAfterInvalidate(); + void qobjectDerived(); private: QQmlEngine engine; @@ -659,6 +660,26 @@ void tst_qqmlcontext::evalAfterInvalidate() QCoreApplication::processEvents(); } +void tst_qqmlcontext::qobjectDerived() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("refreshExpressions.qml")); + + CountCommand command; + // This test is similar to refreshExpressions, but with the key difference that + // we use the QVariant overload of setContextProperty. That way, we test that + // QVariant knowledge that it contains a QObject derived pointer is used. + engine.rootContext()->setContextProperty("countCommand", QVariant::fromValue(&command)); + + // We use a fresh context here to bypass any root-context optimizations in + // the engine + QQmlContext context(engine.rootContext()); + + QObject *o1 = component.create(&context); + + QCOMPARE(command.count, 2); +} + QTEST_MAIN(tst_qqmlcontext) #include "tst_qqmlcontext.moc" |