【问题标题】:PyQt disconnect and connect a signalPyQt 断开和连接信号
【发布时间】:2013-07-14 19:15:53
【问题描述】:

我有一个由 textChanged 信号触发的线程。线程修改了文本,这再次触发了修改文本的线程......并且python崩溃了。 所以想为线程断开信号,修改文本后,重新连接信号。

我需要指定要断开哪个插槽,因为有多个插槽正在监听“textChanged()”。

我收到“参数与任何重载调用都不匹配” - 断开连接部分出错。第一个连接工作,很容易。重新连接可能有效,也可能无效,因为第一个错误,我没有到达那里。

如何正确调用连接/断开连接?

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)

【问题讨论】:

    标签: python qt signals connect


    【解决方案1】:

    断开连接时代码中没有self.A.textedit

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-22
      • 1970-01-01
      • 2018-11-01
      • 2013-12-31
      • 2012-06-20
      • 2016-11-03
      • 2011-05-08
      • 1970-01-01
      相关资源
      最近更新 更多