Commit 8ff69297 authored by Michael Brasser's avatar Michael Brasser
Browse files

Setting Connection's target to null should disconnect implicit target


Change-Id: Id7c8c7080e6db8bb6d09c1df13cddaef047cf611
Task-number: QTBUG-56499
Reviewed-by: default avatarJ-P Nurmi <jpnurmi@qt.io>
Showing with 38 additions and 2 deletions
......@@ -159,9 +159,9 @@ private:
void QQmlConnections::setTarget(QObject *obj)
{
Q_D(QQmlConnections);
d->targetSet = true; // even if setting to 0, it is *set*
if (d->target == obj)
if (d->targetSet && d->target == obj)
return;
d->targetSet = true; // even if setting to 0, it is *set*
foreach (QQmlBoundSignal *s, d->boundsignals) {
// It is possible that target is being changed due to one of our signal
// handlers -> use deleteLater().
......
import QtQuick 2.0
Item {
width: 50
property bool tested: false
Connections { onWidthChanged: tested = true }
}
......@@ -56,6 +56,7 @@ private slots:
void errors();
void rewriteErrors();
void singletonTypeTarget();
void clearImplicitTarget();
private:
QQmlEngine engine;
......@@ -329,6 +330,32 @@ void tst_qqmlconnections::singletonTypeTarget()
delete object;
}
//QTBUG-56499
void tst_qqmlconnections::clearImplicitTarget()
{
QQmlEngine engine;
QQmlComponent c(&engine, testFileUrl("test-connection-implicit.qml"));
QQuickItem *item = qobject_cast<QQuickItem*>(c.create());
QVERIFY(item != 0);
// normal case: fire Connections
item->setWidth(100.);
QCOMPARE(item->property("tested").toBool(), true);
item->setProperty("tested", false);
// clear the implicit target
QQmlConnections *connections = item->findChild<QQmlConnections*>();
QVERIFY(connections);
connections->setTarget(0);
// target cleared: no longer fire Connections
item->setWidth(150.);
QCOMPARE(item->property("tested").toBool(), false);
delete item;
}
QTEST_MAIN(tst_qqmlconnections)
#include "tst_qqmlconnections.moc"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment