Saturday, 15 August 2015

python - PyQt clicked.connect is connected automatically -



python - PyQt clicked.connect is connected automatically -

i'm implementing model view architecture pyqt gui. here's simpler, representative version of code @ moment (since mine waaaay long)

class model(qtgui.qwidget): def __init__(self): self.opendir = '/some/file/dir/' def openfile(self): openfilename = qtgui.qfiledialog.getopenfilename(none, "open file",self.loaddir,"allfiles(*.*)") open = open(openfilename, 'r') ... class view(qtgui.qwidget): def__init__(self): ... self.button = qtgui.qpushbutton("open") ... self.button.clicked.connect(model().openfile()) if __name__ == '__main__': app = qtgui.qapplication(sys.argv) mainwindow = view() mainwindow.show() sys.exit(app.exec_())

however, if haven't pressed button, signal emitted , qfiledialog window comes automatically.

edit 1:

because ran new problem regarding same subject, have opened new question more input.

i think see issue.

self.button.clicked.connect(model().openfile())

should be

self.button.clicked.connect(model().openfile)

in first instance, you're calling openfile method , passing homecoming value "connect". in the second, you're passing method "connect".

python pyqt

No comments:

Post a Comment