The proper use of QSignalMapper

borntonetwork borntonetwork at gmail.com
Wed Jan 17 09:44:33 EST 2007


Hi.

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"))
            self.signalMapper.setMapping(w, idx)

        self.app.connect(self.signalMapper, QtCore.SIGNAL(
            "self.signalMapper.mapped(int)"),
            self.deleteProductIngredient)

    def deleteProductIngredient(self, state, widgetIdx):
        """Delete a product ingredient."""
        print "INSIDE FUNCTION\n"

The idea here is to iterate through several checkbox widgets (named
"chkProductIngredientsDelete_1, _2, etc.) and connect each object's
"stateChanged" signal to the mapper's map() function, then connect the
map() function to the actual slot, deleteProductIngredient().

By the way, I've checked to ensure the statements inside the loop are
being executed.




More information about the Python-list mailing list