简体   繁体   English

如何使用 QFileDialog.getOpenFileName() 函数获取文件路径?

[英]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.我试图在行编辑框中显示用户选择的文件的名称(对于 QGIS python 插件),但是当我运行代码时没有任何反应。

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我希望有人可以帮助我

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM