[PyKDE] Re: "sender" info in Python slot

Andreas Pakulat apaku at gmx.de
Sat Nov 11 10:14:53 GMT 2006

On 11.11.06 09:35:00, Sibylle Koczian wrote:
> Jeremy Sanders wrote:
> > 
> > On Thu, 9 Nov 2006, Andreas Pakulat wrote:
> > 
> > > On 09.11.06 16:43:00, Sibylle Koczian wrote:
> > >> hopefully the subject line isn't too misleading. This is my problem: I 
> > >> would like to connect the "clicked" signal of several buttons to one 
> > >> and the same function - but this function should know which button sent 
> > >> the signal. Example: one button to increase a value, another to 
> > >> decrease it, and one single function which adds '+1' or '-1' depending 
> > >> on the sending button. Or a row of buttons with a letter, and clicking 
> > >> one searches for all words beginning with this letter in a list.
> > >>
> > >> How can I do this? Subclassing QPushButton seems to be a possibility, 
> > >> but is there a simpler way?
> > >
> > > The unclean solution would be to use the sender() function, the proper 
> > > one is to have a look at QSignalMapper.
> > 
> Why unclean (I didn't look yet at the sender() function)?

Then look at the docs. There's a big fat Warning that using sender
violates OO-principles and the signal/slot mechanim. There are quite
some restrictions on sender() which you always have to have in the back
of you head.

> Still trying to get a simple QSignalMapper example to run. In the PyQt4 examples it is used only in mdi.py which isn't exactly simple, right?

Actually I think it is a simple example, you do look at the python
version do you? I guess best idea would be to strip it down to only
include the open and the open-recent-files stuff and remove everything
else. That should make it as simple as it can get.


A visit to a strange place will bring fresh work.

More information about the PyQt mailing list