Pawel
Pawel

Reputation: 39

How to get the path to a file by using the QFileDialog.getOpenFileName() function?

I am trying to display the name of a user-selected file in a line-edit box (for a QGIS python plugin), but nothing happens when I run the code.

Here is my code:

from PyQt5.QtWidgets import QFileDialog

filename = QFileDialog.getOpenFileName(self, 'Open file')[0]
self.dlg.lineEdit.setText(filename)

I hope that somebody can help me

Upvotes: -2

Views: 1228

Answers (1)

mike.pit
mike.pit

Reputation: 1

Here is an exemple of code that is working for me, think about testing your resulting path

fpath, filter = QFileDialog.getOpenFileName(None, "Open project", proj_dir, "XML data files (*.xml)")
if len(fpath) > 0:
    do_stuff

Upvotes: 0

Related Questions