python - PyQt, when button is pressed to connect to a method of different class, code never exits __init__ -


I am currently implementing a model view structure for my PyQt GUI, here is a simple, but currently my code The representative version is.

  class model (QtGui.QWidget): def __init __ (self): super (model, self) .__ init__ () self.openDir = '/ some / file / dir /' Def openfile itself): openFileName = QtGui.QFileDialog.getOpenFileName (none, "Open file", auto.open, "AllFiles (*. *)") OpenFile = Open (openFileName, 'r') ... View Category ( QtGui.QWidget): Def__init __ (self): Super (see, self) .__ init__ () ... self.button = QtGui.QPushButton ("Open") ... self.button.clicked.connect (models (). Openfile) if __name__ == '__main__': app = QtGui.QApplication (sys.argv) mainWindow = see () mainWindow.show () sys.exit (app.exec_ ())  

So when I click on the "open" button, I can see the model class < Code> openfile method, but when I click it, it goes in the model.__init__ but this is actually openFile does not go into the law What do I have to do?


Edit 1: Determine all the errors


Editing 2: For those facing similar problems, here's the solution provided by Fred S. and the definitive code is.

  class model (QtGui.QWidget): def __int __ (self): super (model, self) .__ init__ () self.openDir = '/ some / file / dir /' Def openFile (self): openFileName = QtGui.QFileDialog.getOpenFileName (none, "open file", itself .openDir, "AllFiles (*. *)") OpenFile = open (openFileName, 'r') ... class view (QtGui.QWidget): def__init __ (self): Super (see, self) .__ init__ () ... Self.button = QtGui.QPushButton ("Open") ... self.model = Models () self.button.clicked.connect (self.model.openFile) if __name__ == '__main__': app = QtGui.QApplication ( Sys.argv) mainWindow = see () mainWindow.show () sys.exit (app.exec_ ())  

OK, I do not have PyQt4 on the machine, but I have PySide. When I run the code, I see:

1) Super (model, self) .__ init __ (original) Crash "parent" is not defined.

2) open = open (openFileName, 'r') is very bad

3) self.loaddir does not exist is.

4) But as your question, if I

  self.button.connect (model.openfile)  

should be:

  self. Model = Model () self.button.clicked.connect (self.model.openFile)  

Then the problem is fixed. But it is in PySide, so probably not in PyQt4. Best wishes


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -