From 55b5e30901cd2616d729c61856dabe3bfda5e4f0 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 28 Nov 2013 16:57:41 +0100 Subject: Fix JavaScript signal connect on alias without other handlers The changed handlers for aliases are connected lazily in the engine. QQmlPropertyPrivate::flushSignal is responsible for that and called in other places, for example when installing a onSomeAliasPropertyChanged handler. However we were missing a call to flushSignal when doing onSomeAliasPropertyChanged.connect(...), i.e. using the JavaScript connect API. Task-number: QTBUG-30493 Change-Id: Ia3f008626fd7af3f2cfbdd30d13fb83158bed4d5 Reviewed-by: Albert Astals Cid Reviewed-by: Lars Knoll --- .../qml/qqmlecmascript/data/signalHandlers.qml | 34 ++++++++++++++++++++++ .../auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 7 +++++ 2 files changed, 41 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/qml/qqmlecmascript/data/signalHandlers.qml b/tests/auto/qml/qqmlecmascript/data/signalHandlers.qml index 975be1b2ad..7e85312692 100644 --- a/tests/auto/qml/qqmlecmascript/data/signalHandlers.qml +++ b/tests/auto/qml/qqmlecmascript/data/signalHandlers.qml @@ -57,4 +57,38 @@ QtObject { if (onTestSignal !== undefined) definedHandlerResult = true; } + + property QtObject objWithAlias: QtObject { + id: testObjectWithAlias + + property int count: 0; + property alias countAlias: testObjectWithAlias.count + } + + function testConnectionOnAlias() { + var called = false; + + testObjectWithAlias.onCountAliasChanged.connect(function() { + called = true + }) + + testObjectWithAlias.count++; + return called; + } + + property QtObject objWithAliasHandler: QtObject { + id: testObjectWithAliasHandler + + property bool testSuccess: false + + property int count: 0 + property alias countAlias: testObjectWithAliasHandler.count + onCountAliasChanged: testSuccess = true + } + + function testAliasSignalHandler() { + testObjectWithAliasHandler.testSuccess = false + testObjectWithAliasHandler.count++ + return testObjectWithAliasHandler.testSuccess + } } diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 6b19c13109..660be13f71 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -6060,6 +6060,13 @@ void tst_qqmlecmascript::signalHandlers() QMetaObject::invokeMethod(o, "testSignalHandlerDefined"); QCOMPARE(o->property("definedHandlerResult").toBool(), true); + QVariant result; + QMetaObject::invokeMethod(o, "testConnectionOnAlias", Q_RETURN_ARG(QVariant, result)); + QCOMPARE(result.toBool(), true); + + QMetaObject::invokeMethod(o, "testAliasSignalHandler", Q_RETURN_ARG(QVariant, result)); + QCOMPARE(result.toBool(), true); + delete o; } -- cgit v1.2.3