"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) self.actionLoad_Dev_Defs.setObjectName(_fromUtf8("actionLoad_Dev_Defs")) self.menuFile.addAction(self.actionLoad_Dev_Defs)
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.setupUi(self) 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.
Hi and welcome to devnet,
If my PyQt is not to rusty, you should change your SLOT to
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'
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
Since you have it working now, please update the thread title prepending [solved] so other forum users my know a solution has been found :)