Setting Connection's target to null should disconnect implicit target
Change-Id: Id7c8c7080e6db8bb6d09c1df13cddaef047cf611 Task-number: QTBUG-56499 Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
This commit is contained in:
parent
291223876b
commit
8ff69297ee
|
@ -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().
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
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"
|
||||
|
|
Loading…
Reference in New Issue