user2366975
user2366975

Reputation: 4710

PyQt disconnect and connect a signal

I have a thread that is triggered by a textChanged-Signal. The thread modifies the text, which again triggers the thread, that modifies the text...and python crashes. So I want to disconnect the signal for the thread, and after the text is modified, reconnect the signal.

I need to specify which slot to disconnect, because there are more than one slots listening to "textChanged()".

I get an "arguments did not match any overloaded call" - error at the disconnect part. The first connect works, easy. The re-connect may work or not, I don't get there because of the first error.

How do I call the connect/disconnect correctly?

class A:
    self.textedit=QTextEdit()
    self.textedit.setText("Bla")

    self.connect(self.textedit, SIGNAL("textChanged()"), self.refresh)
    self.thread=Worker(self)

    def refresh(self):
        self.thread.start()

class Worker:
    def __init__(self, A)
        self.A=A

    def run(self):
        self.A.disconnect("textChanged()", self.A.refresh)
        .
        . do sth.
        . self.A.textedit.setText("modified Bla")
        self.A.connect(self.A.textedit, SIGNAL("textChanged()"), self.A.refresh)

Upvotes: 1

Views: 4017

Answers (1)

Aleksandar
Aleksandar

Reputation: 3661

There is no self.A.textedit in your code when disconnecting:

self.A.disconnect(self.A.textedit, "textChanged()", self.A.refresh)

Upvotes: 1

Related Questions