"triggered()" Signal for Menu Item is being sent on App start up

  • I am just starting developing/evaluating QT and I am seeing a weird issue. I have a very simple application, currently its a window with a single Menu Item. I created this in the QT Designer and generated a python file with pyuic4. The QT Designer has no signal/slots defined. Here part of the generated code in question:

        self.actionLoad_Dev_Defs = QtGui.QAction(MainWindow)

    I have another file that creates an instance of my generated class and attempts to setup a Signal to that Menu Item

        self.ui = Ui_MainWindow()
        self.ui.actionLoad_Dev_Defs.connect(self.ui.actionLoad_Dev_Defs, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT(self.loadDefinitions()))

    The problem is that self.loadDefinitions() is being called immediately when the application starts.
    Any help is appreciated.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    If my PyQt is not to rusty, you should change your SLOT to QtCore.SLOT(self.loadDefinitions)

    Hope it helps

  • I tried that and it caused this error.

    File "/Users/sabbamonte/Dev/MainWindow.py", line 12, in init
    self.ui.actionLoad_Dev_Defs.connect(self.ui.actionLoad_Dev_Defs, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT(self.loadDefinitions))
    TypeError: SLOT(str): argument 1 has unexpected type 'method'

  • Lifetime Qt Champion

    Are you using PyQt or PySide ?

    If the first one: here is the guide to setup your signals and slots using the new syntax

  • I was looking at this page for a while and I am not trying to create a new Signal I am trying to connect to the signal of an already created Menu Item. Also when I look at the signature for the connect function in QObject.py it looks like this:

    def connect(self, QObject, SIGNAL, *args, **kwargs):

    There is no connect function that takes a single argument. I am using Python 3.4.3 and QT 4.11.5

  • I figured out the problem if anyone comes accross this thread I hope this helps.

        self.ui.actionLoad_Dev_Defs.connect(self.ui.actionLoad_Dev_Defs, QtCore.SIGNAL("triggered()"), self.loadDefinitions)

    no need for the QtCore.SLOT(. . . ) on that third param

  • Lifetime Qt Champion

    Good !

    Since you have it working now, please update the thread title prepending [solved] so other forum users my know a solution has been found :)

Log in to reply