-2

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

sxeros
  • 668
  • 6
  • 21
Pawel
  • 39
  • 1
  • Just these 3 lines of code won't work, I guess you have more code where you have these 3 lines somewhere included? if yes please include them into the question – sxeros Feb 04 '20 at 14:34
  • The code is part of a large code for a QGIS plugin built from a QT creator template, so unfortunately I cant post it all here. – Pawel Feb 05 '20 at 07:39
  • 'All' is not needed. Just follow these [Minimal Reproduction Example](https://stackoverflow.com/help/minimal-reproducible-example) Guidelines – sxeros Feb 05 '20 at 07:44

1 Answers1

0

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
mike.pit
  • 1
  • 1