diff options
-rw-r--r-- | src/qml/jsruntime/qv4qobjectwrapper.cpp | 7 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/data/signalHandlers.qml | 34 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 7 |
3 files changed, 47 insertions, 1 deletions
diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index c48b6bf61d..85e6878f7b 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -848,7 +848,7 @@ ReturnedValue QObjectWrapper::method_connect(CallContext *ctx) QPair<QObject *, int> signalInfo = extractQtSignal(ctx->callData->thisObject); QObject *signalObject = signalInfo.first; - int signalIndex = signalInfo.second; + int signalIndex = signalInfo.second; // in method range, not signal range! if (signalIndex < 0) V4THROW_ERROR("Function.prototype.connect: this object is not a signal"); @@ -882,6 +882,11 @@ ReturnedValue QObjectWrapper::method_connect(CallContext *ctx) slot->thisObject = thisObject; slot->function = f; + if (QQmlData *ddata = QQmlData::get(signalObject)) { + if (QQmlPropertyCache *propertyCache = ddata->propertyCache) { + QQmlPropertyPrivate::flushSignal(signalObject, propertyCache->methodIndexToSignalIndex(signalIndex)); + } + } QObjectPrivate::connect(signalObject, signalIndex, slot, Qt::AutoConnection); return Encode::undefined(); 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; } |