Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QtQml/Connections: Only reconnect signals if target is valid #344

Merged
merged 1 commit into from
Oct 12, 2016

Conversation

stephenmdangelo
Copy link
Member

No description provided.

@ChALkeR
Copy link
Member

ChALkeR commented Oct 10, 2016

Do you have a testcase for this to compare the behavior with Qt QML?

@stephenmdangelo
Copy link
Member Author

I've added a test case for this. Travis CI seems to have failed for an unrelated reason (seems like just a timing problem).

Qt QML behaviour seems to be broken (at least in Qt 5.4 that I'm testing with). Setting target to null properly disconnects signals when done in a Binding, but not when done via JavaScript.

This works as expected:

import QtQuick 2.0

Item {
    id: root
    property bool should_connect: true
    MouseArea {
        id: mouse_area
        anchors.fill: parent
        Connections {
            id: connections
            target: root.should_connect ? mouse_area : null
            onPressedChanged: {
                console.log("pressed changed")
            }
        }
        onClicked: {
            root.should_connect = !root.should_connect
            console.log("connections target", connections.target)
        }
    }
}

This doesn't:

import QtQuick 2.0

Item {
    MouseArea {
        anchors.fill: parent
        Connections {
            id: connections
            onPressedChanged: {
                console.log("pressed changed")
            }
        }
        onClicked: {
            console.log("connections target", connections.target)
            connections.target = null
            console.log("connections target", connections.target)
        }
    }
}

Documentation says (http://doc.qt.io/qt-5/qml-qtqml-connections.html#target-prop):

If set to null, no connection is made and any signal handlers are ignored until the target is not null.

@ChALkeR
Copy link
Member

ChALkeR commented Oct 11, 2016

@stephenmdangelo the Timer test being flaky is a known issue, see #229. I disabled that test in 97bf659.

@ChALkeR
Copy link
Member

ChALkeR commented Oct 12, 2016

@stephenmdangelo

Note, this works:

import QtQuick 2.0

Item {
    MouseArea {
        id: mouse_area
        anchors.fill: parent
        Connections {
            id: connections
            target: mouse_area // commenting out this line breaks the test
            onPressedChanged: {
                console.log("pressed changed")
            }
        }
        onClicked: {
            console.log("connections target", connections.target, mouse_area)
            connections.target = null
            console.log("connections target", connections.target, mouse_area)
        }
    }
}

Reported as https://bugreports.qt.io/browse/QTBUG-56499.

@ChALkeR
Copy link
Member

ChALkeR commented Oct 12, 2016

LGTM, merging.

@ChALkeR ChALkeR merged commit ffdf42e into qmlweb:master Oct 12, 2016
@ChALkeR
Copy link
Member

ChALkeR commented Nov 22, 2016

@stephenmdangelo, Qt bug was fixed in https://codereview.qt-project.org/173937/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants