PySide2 set base dir in QFileDialog.getOpenFileNames()
-
Hi,
I'm very new to python.
I'm trying to open QFileDialog.getOpenFileNames() and set base dir. If I do it as follows:file_names = QFileDialog.getOpenFileNames(self, self.tr("Select one or more LAS files to open"), "C:/Program Files", "LAS (*.las);; all (*.*)")
It works and the current directory is "C:/Program Files"
Now I want to set current directory as base.
To do so I write:current_dir = os.getcwdb() file_names = QFileDialog.getOpenFileNames(self, self.tr("Select one or more LAS files to open"), current_dir, "LAS (*.las);; all (*.*)")
I get the error:
FIXME Subscripted generics cannot be used with class and instance checks
Traceback (most recent call last):
File "C:/.../lasreader.py", line 19, in on_add_btn_clicked
file_names = QFileDialog.getOpenFileNames(self, self.tr("Select one or more LAS files to open"),
TypeError: 'PySide2.QtWidgets.QFileDialog.getOpenFileNames' called with wrong argument types:
PySide2.QtWidgets.QFileDialog.getOpenFileNames(LasReader, str, bytes, str)
Supported signatures:
PySide2.QtWidgets.QFileDialog.getOpenFileNames(typing.Union[PySide2.QtWidgets.QWidget, NoneType] = None, str = '', str = '', str = '', str = '', PySide2.QtWidgets.QFileDialog.Options = Default(QFileDialog.Options)) -
@Please_Help_me_D use
os.getcwd()
instead ofos.getcwdb()
-
@eyllanesc thank you!
-
@Please_Help_me_D said in PySide2 set base dir in QFileDialog.getOpenFileNames():
os.getcwdb()
Even better, don't use a Python function for passing a parameter to a Qt method when a suitable Qt one is available:
QDir::currentPath()
. At least that is returned in the internal format used by Qt for paths which is technically what is expected byQFileDialog.getOpenFileNames()
.