[PyKDE] Signals and Slots in PyQt4

Baz Walter bazwal at ftml.net
Mon Dec 19 17:02:47 GMT 2005

On Sunday 18 Dec 2005 22:04, Phil Thompson wrote:
> On Sunday 18 December 2005 6:33 pm, Baz Walter wrote:
> > Hello
> >
> > When disconnecting a signal from a python slot, if the connection has not
> > already been made, it produces the error: 'RuntimeError: Slot hasn't been
> > connected'. However, QObject.disconnect gives a boolean result on
> > success/failure. So is this error really necessary? (With unconnected qt
> > slots, disconnect just returns false).
> I'll take a look at that.
> > Also, given that PYSIGNAL has been removed from PyQt4, would it now make
> > sense to support the full SIGNAL/SLOT syntax for python member functions?
> > That is, if MyCustomClass emits a "stuffHappened" signal, should it be
> > possible to connect it to MyCustomClass.handleStuff() like this:
> >
> > 	self.connect(self, QtCore.SIGNAL("stuffHappened"),
> > 		     self, QtCore.SLOT("handleStuff"))
> >
> > This syntax isn't all sugar. It's also more flexible if the receiver
> > object and the slot can be passed independantly.
> I don't see how that's more flexible.
> Phil

I was thinking of the added flexibilty of "call by name" here. But in any 
case, what really motivated my question is that the syntax for signal/slot 
connections is not completely interchangeable between python and qt. So it 
might be good for newcomers to pyqt if there was "one obvious way to do it" 
and that that way was closer to what is in the qt docs. But having said that, 
using SLOT in the way I suggested would not help much because the format of 
the string argument would still be quite different. So, all in all, it is 
better to just allow a python callable to be passed as an alternative to a qt 
receiver/slot pair. I thought there would be quite a few places where this 
could be done, but there are only half a dozen or so (not counting QObject 
and QMetaObject). These are QTimer.singleShot, QHostInfo.lookupHost, various 
addAction slots in QMenu, QMenuBar and QToolBar, and the constructor for 
QShortcut (which I think has already been done).

(BTW - I think PyQt4 is already a superb bit of kit, so I hope I am not 
moaning too much! Only the best is truly worth trying to make better :)

Baz Walter

More information about the PyQt mailing list