Skip to content

Commit

Permalink
Add test verifying that QObject-derived pointer is passed correctly.
Browse files Browse the repository at this point in the history
Ensure that an object derived from QObject is correctly passed to
an invokable function from QML.

Change-Id: I71eefe8c480e1f1574804d05244b53f29c7fbf0d
Reviewed-by: Martin Jones <martin.jones@nokia.com>
  • Loading branch information
Matthew Vogt authored and Qt by Nokia committed Feb 22, 2012
1 parent 6f96bf2 commit 136f235
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
@@ -0,0 +1,17 @@
import QtQuick 2.0
import Qt.test 1.0

MyQmlObject {
id: root
stringProperty: 'hello'
property var child

property bool result: false

Component.onCompleted: {
child = invokable.createMyQmlObject('goodbye');

result = (invokable.getStringProperty(root) == 'hello') &&
(invokable.getStringProperty(child) == 'goodbye');
}
}
Expand Up @@ -235,6 +235,7 @@ private slots:
void rewriteMultiLineStrings();
void revisionErrors();
void revision();
void invokableWithQObjectDerived();

void automaticSemicolon();
void unaryExpression();
Expand Down Expand Up @@ -6017,6 +6018,45 @@ void tst_qdeclarativeecmascript::tryStatement()
}
}

class CppInvokableWithQObjectDerived : public QObject
{
Q_OBJECT
public:
CppInvokableWithQObjectDerived() {}
~CppInvokableWithQObjectDerived() {}

Q_INVOKABLE MyQmlObject *createMyQmlObject(QString data)
{
MyQmlObject *obj = new MyQmlObject();
obj->setStringProperty(data);
return obj;
}

Q_INVOKABLE QString getStringProperty(MyQmlObject *obj)
{
return obj->stringProperty();
}
};

void tst_qdeclarativeecmascript::invokableWithQObjectDerived()
{
CppInvokableWithQObjectDerived invokable;

{
QDeclarativeEngine engine;
engine.rootContext()->setContextProperty("invokable", &invokable);

QDeclarativeComponent component(&engine, testFileUrl("qobjectDerivedArgument.qml"));

QObject *object = component.create();

QVERIFY(object != 0);
QVERIFY(object->property("result").value<bool>() == true);

delete object;
}
}

QTEST_MAIN(tst_qdeclarativeecmascript)

#include "tst_qdeclarativeecmascript.moc"

0 comments on commit 136f235

Please sign in to comment.