The proper use of QSignalMapper
borntonetwork
borntonetwork at gmail.com
Wed Jan 17 21:04:19 EST 2007
Thanks, David, for you help.
When I change the slot function to what you show in your second
example, I get the same results: nothing. When I change it to what you
have in your first example, I get the following:
Object::connect: No such slot QApplication::map()
Object::connect: (sender name: 'chkProductIngredientsDelete_1')
Object::connect: (receiver name: 'main.py')
Object::connect: No such slot QApplication::map()
Object::connect: (sender name: 'chkProductIngredientsDelete_2')
Object::connect: (receiver name: 'main.py')
Object::connect: No such slot QApplication::map()
Object::connect: (sender name: 'chkProductIngredientsDelete_3')
Object::connect: (receiver name: 'main.py')
Object::connect: No such slot QApplication::map()
Object::connect: (sender name: 'chkProductIngredientsDelete_4')
Object::connect: (receiver name: 'main.py')
Object::connect: No such slot QApplication::map()
Object::connect: (sender name: 'chkProductIngredientsDelete_5')
Object::connect: (receiver name: 'main.py')
Object::connect: No such slot QApplication::map()
Object::connect: (sender name: 'chkProductIngredientsDelete_6')
Object::connect: (receiver name: 'main.py')
David Boddie wrote:
> 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