Your code is almost right. You just need to connect the signals to a lambda
with a default argument, like this:
for item in testItems:
action = self.popMenu.addAction('Selected %s' % item)
action.triggered.connect(
lambda chk, item=item: self.printItem(item))
The default argument ensures that each lambda
gets a copy of the current loop variable. Also note that an initial chk
argument is also required. This is because the triggered
signal sends its current checked-state (true or false) by default, which would clobber the item
argument of the lambda
.
Finally, I would urge to use the new-style syntax when connecting signals - the old style can be very error-prone, and is far less pythonic.