pyqt/python-qt5

Retrieve the true file path using QFileDialog

tdard opened this issue · 0 comments

tdard commented

Hi,

I try to get the path to an existing file, but the resulting path has a weird prefix, like it is moved in a temporary directory:
for a file located at /home/<user_name>/<folder_name>/<file_name.extension> I obtain the following path:
/run/user/1000/doc/daf242de/<file_name.extension>

Here is the sample code (tested on Ubuntu)

if __name__ == "__main__":
    from PyQt5.QtWidgets import QApplication, QFileDialog

    app = QApplication([])

    dialog = QFileDialog()
    dialog.setFileMode(QFileDialog.ExistingFile)  # Accept a single file that exists
    if dialog.exec():
        file_path = dialog.selectedFiles[0]
        print(file_path)

Do you know if it is normal, and how I could I configure the dialog such that I could retrieve the true path of the file I'm searching for?
Kind regards