Nameless
Nameless

Reputation: 2366

Binding menu action in PyQT

This is probably something stupid, but I really can't figure it out myself.

I'm using wrapper class for QtGui.QAction. Code goes like this:

class Action_Abstract(Abstract):

    def __init__(self, app, menu):
        Abstract.__init__(self, app)

        action = QtGui.QAction(self.get_window())
        action.setText('Text')
        action.triggered.connect(self.execute)

        menu.addAction(action)

    def execute(self):
        print 'Called'

No errors thrown, action appears in menu. But self.execute is not called, when I click on action. Funny thing is, if I replace self.execute with QtGui.qApp.quit from example, it works.

What am I missing here?

Upvotes: 0

Views: 6065

Answers (1)

wmeyer
wmeyer

Reputation: 3496

Do you keep a reference to the instance of Action_Abstract?

If you don't, the problem may be that the Python object is garbage-collected which will also cut the connection to self.execute.

Upvotes: 2

Related Questions