From e92c4b557b07e34a47615a1f7f9a5aff9e981aa6 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 27 Oct 2009 19:39:50 +1000 Subject: Support return values in synthesized methods --- src/declarative/qml/qmlcompiler.cpp | 1 + src/declarative/qml/qmlvmemetaobject.cpp | 6 ++++-- tests/auto/declarative/qmlecmascript/data/methods.3.qml | 7 +++++++ tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp | 7 +++++++ 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 tests/auto/declarative/qmlecmascript/data/methods.3.qml diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index 60282dc..ad74446 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -2234,6 +2234,7 @@ bool QmlCompiler::buildDynamicMeta(QmlParser::Object *obj, DynamicMetaMode mode) } sig.append(")"); QMetaMethodBuilder b = builder.addSlot(sig); + b.setReturnType("QVariant"); b.setParameterNames(s.parameterNames); ((QmlVMEMetaData *)dynamicData.data())->methodCount++; diff --git a/src/declarative/qml/qmlvmemetaobject.cpp b/src/declarative/qml/qmlvmemetaobject.cpp index 3e1d931..83f904b 100644 --- a/src/declarative/qml/qmlvmemetaobject.cpp +++ b/src/declarative/qml/qmlvmemetaobject.cpp @@ -269,10 +269,11 @@ int QmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) QString code = QString::fromRawData(body, data->bodyLength); + QVariant rv; if (0 == (metaData->methodData() + id)->parameterCount) { QmlExpression expr(ctxt, code, object); expr.setTrackChange(false); - expr.value(); + rv = expr.value(); } else { QmlContext newCtxt(ctxt); QMetaMethod m = method(_id); @@ -281,8 +282,9 @@ int QmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) newCtxt.setContextProperty(QString::fromLatin1(names.at(ii)), *(QVariant *)a[ii + 1]); QmlExpression expr(&newCtxt, code, object); expr.setTrackChange(false); - expr.value(); + rv = expr.value(); } + if (a[0]) *reinterpret_cast(a[0]) = rv; } return -1; } diff --git a/tests/auto/declarative/qmlecmascript/data/methods.3.qml b/tests/auto/declarative/qmlecmascript/data/methods.3.qml new file mode 100644 index 0000000..2efcf6a --- /dev/null +++ b/tests/auto/declarative/qmlecmascript/data/methods.3.qml @@ -0,0 +1,7 @@ +import Qt 4.6 + +Object { + function testFunction() { return 19; } + + property int test: testFunction() +} diff --git a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp index a0e65c5..67a98b1 100644 --- a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp +++ b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp @@ -152,6 +152,13 @@ void tst_qmlecmascript::methods() QCOMPARE(object->methodCalled(), false); QCOMPARE(object->methodIntCalled(), true); } + + { + QmlComponent component(&engine, TEST_FILE("methods.3.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + QCOMPARE(object->property("test").toInt(), 19); + } } void tst_qmlecmascript::bindingLoop() -- cgit v0.12