[PyQt] simpler 'connect' function

Phil Thompson phil at riverbankcomputing.co.uk
Thu Jan 17 23:34:58 GMT 2008


On Thursday 17 January 2008, Ewald de Wit wrote:
> On Thursday 17 January 2008 18:27:19 Peter Shinners wrote:
> > > 	button.clicked.connect(self.onButtonClicked)
> >
> > Is there a clean way to handle signals with the same name that take
> > different arguments? Here's an idea I can think of for QComboBox.
> >
> > combo.activated[int].connect(callback1)
> > combo.activated[QString].connect(callback2)

The problem with this approach is that you can't represent all C++ argument 
types with Python types.

> A simpler way would be to just give the signal objects a different name,
> like activatedInt and activatedString. It's the easiest way to uniquely
> specify which signal you mean.

The problem with this is that things can get clunky - 
focusChangedQWidgetPtrQWidgetPtr for example.

Those that don't like strings because they can't be type checked are wrong. 
They can be type checked against Qt signals (see 
QMetaObject::indexOfSignal()). The problem is that they can't be 
distinguished from Python signals which are not pre-defined.

My prefered option at the moment is just not to support Python signals in any 
new approach - short-circuit signals would have to be used instead (which 
don't have parentheses and are therefore easy to distinguish from Qt 
signals).

Phil


More information about the PyQt mailing list