Grav Grav - 3 months ago 12
Python Question

Trouble with object-based QSignalMapper

I am trying to set up a signal-slot arrangement in PyQt where the signal transmits a lot of information. I want to use a

QObject
as a carrier by setting the various information I want to transmit as attributes of the
QObject
. In theory, this should work - there is a
QSignalMapper.setMapping()
overload which takes a sender and a
QObject
as arguments.

Here's the reduced code:

self.mapper = QtCore.QSignalMapper()
self.timeline.finished.connect(self.mapper.map)
carrier = QtCore.QObject()
carrier.contents = (item1, item2)
self.mapper.setMapping(self.timeline, carrier)
self.portalMapper.mapped.connect(self.report)

def report(self, carrierObject):
print 'Triggered'


Unfortunately it doesn't work. I've traced the problem to the
setMapping
function by process of elimination.

This same scheme will work just fine if I switch out the
QObject
with an
int
. It also doesn't have anything to do with the attributes I added to the
QObject
- using a fresh-out-of-the-box
QObject
causes the same issue.

It seems like there is something going on here with this specific overload of the
setMapping
function. Any ideas about what the issue is here?

Answer Source

Thanks to @ekhumoro's suggestion to skip the QSignalMapper approach entirely and just create a custom signal. Worked like a charm.