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

How does qtrio._qt.connection() handle signals and slots getting destroyed #97

Open
altendky opened this issue Jul 17, 2020 · 1 comment

Comments

@altendky
Copy link
Owner

Raised at: innodatalabs/triq#5 (comment)

Even if it ought to 'just work out' there should probably be tests added. Though maybe @nicoddemus can elaborate on a scenario where we retain a reference to a signal or slot and they 'go away'. Or perhaps that's the issue and we shouldn't be retaining strong references at all and need to switch to weakrefs.

@nicoddemus
Copy link

Here's a quick example demonstrating how connections are automatically undone if one of the sides is destroyed:

from PyQt5.QtWidgets import QApplication, QPushButton


class MyObject:

    def __init__(self, clicks):
        self.clicks = clicks

    def on_click(self):
        self.clicks.append(1)


def main():
    app = QApplication([])

    clicks = []
    obj = MyObject(clicks)

    button = QPushButton()
    button.clicked.connect(obj.on_click)

    button.clicked.emit()
    assert clicks == [1], obj.clicks

    del obj
    # clicking on the button again won't append to the list because the connection
    # is undone automatically
    button.clicked.emit()
    assert clicks == [1], obj.clicks


main()

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

No branches or pull requests

2 participants