python - PyQt clicked.connect is connected automatically -


I am currently implementing a model view structure for my PyQt GUI here but my code is a simple but The representative version (since I am really tall)

  class model (QtGui.QWidget): def __init __ (self): self.openDir = '/ some / file / dir / darffile Self): OpenFileName = QtGui.QFileDialog.getOpenFileName (none, "Open file", auto.loaddie, "Allfiles (*. *)") Open = open (openFileName, 'r') ... see category (QtGui. QWidget): def__init __ (auto ): ... self.button = QtGui.QPushButton ("Open") ... self.button.clicked.connect (model (). OpenFile ()) If __name__ == '__main__': app = QtGui.QApplication ( Sys.argv) mainWindow = see () mainWindow.show () sys.exit (app.exec_ ())  

However, even if I have not pressed the button, then The signal has already been emitted and the QFileDialog window appears automatically.


Editing 1:

Because I went to a new problem about the same subject, I opened a new question for more input.

I think I am seeing this issue.

  self.button .clicked.connect (model (). Openfile ()) should be  

  self .button.clicked.connect (Model (. OpenFile)  

In the first example, you are calling the OpenFile method and are passing the return value for "Connect". In the second, you are going through the "connect" method.


Comments