Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. PySide2 set base dir in QFileDialog.getOpenFileNames()

PySide2 set base dir in QFileDialog.getOpenFileNames()

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Please_Help_me_DP Offline
    Please_Help_me_DP Offline
    Please_Help_me_D
    wrote on last edited by Please_Help_me_D
    #1

    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))

    JonBJ 1 Reply Last reply
    0
    • eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by
      #2

      @Please_Help_me_D use os.getcwd() instead of os.getcwdb()

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      Please_Help_me_DP 1 Reply Last reply
      2
      • eyllanescE eyllanesc

        @Please_Help_me_D use os.getcwd() instead of os.getcwdb()

        Please_Help_me_DP Offline
        Please_Help_me_DP Offline
        Please_Help_me_D
        wrote on last edited by
        #3

        @eyllanesc thank you!

        1 Reply Last reply
        0
        • Please_Help_me_DP Please_Help_me_D

          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))

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @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 by QFileDialog.getOpenFileNames().

          Please_Help_me_DP 1 Reply Last reply
          3
          • JonBJ JonB

            @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 by QFileDialog.getOpenFileNames().

            Please_Help_me_DP Offline
            Please_Help_me_DP Offline
            Please_Help_me_D
            wrote on last edited by
            #5

            @JonB yes, thank you for the hint!

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved