为什么PyQt connect()语法如此冗长?

j b*_*j b 8 python qt qt4 pyqt pyqt4

我只是学习PyQt并查看信号和插槽机制.我对冗长的语法感到困惑.为什么我们有:

self.connect(dial, SIGNAL("valueChanged(int)"), spinbox.setValue)
Run Code Online (Sandbox Code Playgroud)

我更愿意写下面的内容:

self.connect(dial.valueChanged, spinbox.setValue)
Run Code Online (Sandbox Code Playgroud)

任何人都可以告诉我为什么connect()语法需要如此明确/详细?

Lup*_*uch 28

你可以使用PyQt的新风格信号,这些信号不那么冗长:

self.connect(dial, SIGNAL("valueChanged(int)"), spinbox.setValue)
Run Code Online (Sandbox Code Playgroud)

变为:

dial.valueChanged.connect(spinbox.setValue)
Run Code Online (Sandbox Code Playgroud)