Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is PyQt connect() syntax so verbose?

I'm just learning PyQt and looking at the Signals and Slots mechanism. I'm a bit baffled by the verbose syntax. Why do we have:

self.connect(dial, SIGNAL("valueChanged(int)"), spinbox.setValue)

I would much prefer to write the following:

self.connect(dial.valueChanged, spinbox.setValue)

Can anyone tell me why the connect() syntax needs to be so explicit/verbose?

like image 937
j b Avatar asked Oct 27 '10 09:10

j b


2 Answers

You can use PyQt's new style signals which are less verbose:

self.connect(dial, SIGNAL("valueChanged(int)"), spinbox.setValue)

Becomes:

dial.valueChanged.connect(spinbox.setValue)
like image 58
Luper Rouch Avatar answered Sep 30 '22 07:09

Luper Rouch


Luper's answer is much better than this one, but for the sake of completeness...

The ugly "old style" syntax is an anachronism from the C++ world - just look at the syntax those guys have to work with! Yucky...

like image 38
danodonovan Avatar answered Sep 30 '22 06:09

danodonovan