[PyQt] PyQT Dynamic Signal Handling

Sebastian Köln sebk at rynx.org
Wed May 14 04:57:53 BST 2014

Hallo Marc,

first the solution:

The issues that I found with you code are:
QSignalMapper::mapped is an overloaded signal. Thus PyQt picks one (it appears 
to be the int version) and connects that. This does not work, as you are 
providing a string. (To connect the right signal, see [1].)

Now you are attempting to connect the  QSignalMapper::mapped signal to your 
pyqtSignal Handler.button_map, which has no signature. So again PyQt does not 
know, which signal to connect (and raises an error).
> TypeError: connect() failed between mapped(int) and button_map()

The smallest change from your code is to add the signature to button_map by 
>	button_map = QtCore.pyqtSignal(str)
and connecting the correct signal from thesignalMapper
> 	self.signalMapper.mapped[str].connect(self.button_map) 

You could also directly connect that to your channel_clicked method as I have 
done in link above.

greetings, Sebastian


> Hey all!
> I've been developing an app using PyQT for a few months now and I've run
> into a stumbling block. I hope that it is alright to ask support questions
> on this mailing list. If it is not, just let me know and I'll look for
> another support medium.
> Basically, I have an array that I want to create buttons out of.  I need to
> do it dynamically, as the array can and will change frequently.  I've come
> across QSignalMapper and believe it will do exactly what I need, however
> after getting all the code written out, the buttons generate but do not
> appear to emit any signals that are being recognized by my handler. I've
> linked [1] the relavent code below as a pastebin.
> Thanks for any help you guys can provide!
> [1] http://pastebin.com/qXfB1FZz

More information about the PyQt mailing list