[Tutor] QT Python: How to re-use the return value of fileDialog.openFileName() ?

Sunitha Misra sunithanc at gmail.com
Mon May 27 04:53:23 CEST 2013


tutor at python.org

Hello,
I am trying to write a UI for my utility, using QT-Python. I first launch a
GUI and click on a toolButton to open up the directory structure, from
which I select a particular file.

self.fileDialog = QtGui.QFileDialog()

QtCore.QObject.connect(self.toolButton,
QtCore.SIGNAL(_fromUtf8("clicked()")), self.fileDialog.getOpenFileName)

So far so good.

How do I store the return value of getOpenFileName?

For example, if I do the following, it gives error:
QtCore.QObject.connect(self.toolButton,
QtCore.SIGNAL(_fromUtf8("clicked()")),
(filepath=self.fileDialog.getOpenFileName))

The reason I want to store the return value is because I want to capture
the filename/path that getOpenFilename returned in a string so I can copy
it to a lineEdit space as below:

self.lineEdit.setText(filepath)

text = self.lineEdit.text()

(If I do the following, it will re-lauch the directory list), which I don't
want.
self.lineEdit.setText(self.fileDialog.getOpenFileName())

Thanks in advance.
SM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130526/cd1527bc/attachment-0001.html>


More information about the Tutor mailing list