The proper use of QSignalMapper

David Boddie david at boddie.org.uk
Wed Jan 17 16:51:40 CET 2007


borntonetwork wrote:

> I am trying to implement QTCore.QSignalMapper using PyQT. I finally got
> to a point where I don't receive any compile or runtime error messages,
> but I also do not see the final slot function fire off. Here is a
> snippet of the code:
>
>         self.signalMapper = QtCore.QSignalMapper(window)
>         # Use qsignalmapper to use of one slot function for multiple
>         # widgets. The map() function sends the slot an extra param
>         # that identifies the sender.
>         for idx in range(1, maxIngredients+1):
>             wName = 'chkProductIngredientsDelete_'+str(idx)
>             w = self.__dict__[wName]
>             self.app.connect(w, QtCore.SIGNAL("stateChanged(int)"),
>                 self.signalMapper,
>                 QtCore.SLOT("self.signalMapper.map"))

You need to pass the C++ signature to the SLOT() function. I believe
you want the form that does not accept any arguments:

             self.app.connect(w, QtCore.SIGNAL("stateChanged(int)"),
                 self.signalMapper,
                 QtCore.SLOT("map()"))

Alternatively, you can pass the slot directly to the function:

             self.app.connect(w, QtCore.SIGNAL("stateChanged(int)"),
                 self.signalMapper.map)

PyQt accepts Python methods as slots, without requiring that they be
wrapped in calls to SLOT().

David




More information about the Python-list mailing list