Search code examples
pythonpyqtpyqt4signals-slots

Tying PyQt4 QAction triggered() to local class callable doesn't seem to work. How to debug this?


I create this object when I want to create a QAction. I then add this QAction to a menu:

class ActionObject(object):
  def __init__(self, owner, command):
    action = QtGui.QAction(command.name, owner)
    self.action = action
    self.command = command
    action.setShortcut(command.shortcut)
    action.setStatusTip(command.name)
    QtCore.QObject.connect(action, QtCore.SIGNAL('triggered()'), self.triggered)
  def triggered(self):
    print("got triggered " + self.command.id + " " + repr(checked))

Unfortunately, when the menu item is selected, the 'triggered' function is not called. QtCore.QObject.connect() returns True. Nothing is printed on the console to indicate that anything is wrong, and no exception is thrown.

How can I debug this? (or, what am I doing wrong?)


Solution

  • Maybe a bit late but I had the same problem and I solved it by changing: class ActionObject(object) to class ActionObject()