PDA

View Full Version : PyQT connect problem



di_zou
5th November 2009, 20:51
I have this code:



def CreateActions(self):
global openAct
openAct = QtGui.QAction("Open", self)
openAct.setShortcut("Ctrl+O")
self.connect(openAct, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("self.Open(self)"))
def Open(self):
print "test\n"


When I click the open button in my menu, nothing happens. When the code runs there are no errors. What is the problem?

di_zou
6th November 2009, 17:03
I have this now:



def CreateActions(self):
global openAct
openAct = QtGui.QAction("Open", self)
openAct.setShortcut("Ctrl+O")
#openAct.triggered.connect(self.Open())
QtCore.QObject.connect(openAct, QtCore.SIGNAL("triggered()"), self, self.Open())
def CreateMenus(self):
menubar = self.menuBar()
fileMenu = menubar.addMenu("&File")
fileMenu.addAction(openAct)
def Open(self):
print "test\n"
fileName = QtGui.QFileDialog. \
getOpenFileName(self, "Open File",
QtCore.QDir.currentPath(),
"NetDMF Files (*.xml *.xmf *.xmn)")

The "test" is printed, but the Open() method is executed as soon as I run the code. The program does not wait for me to click the Open action.

If I have this code:


def CreateActions(self):
global openAct
openAct = QtGui.QAction("Open", self)
openAct.setShortcut("Ctrl+O")
#openAct.triggered.connect(self.Open())
QtCore.QObject.connect(openAct, QtCore.SIGNAL("triggered()"), self, self.Open())
def CreateMenus(self):
menubar = self.menuBar()
fileMenu = menubar.addMenu("&File")
fileMenu.addAction(openAct)
def Open(self):
print "test\n"


I get this error:
TypeError: argument 4 of QObject.connect() has an invalid type