Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QFileDialog not started in needs dir
Qt 6.11 is out! See what's new in the release blog

QFileDialog not started in needs dir

Scheduled Pinned Locked Moved Unsolved Qt for Python
21 Posts 5 Posters 11.7k Views 1 Watching
  • 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.
  • M Offline
    M Offline
    Mihaill
    wrote on last edited by
    #1

    Hi!
    I use Ubuntu 20.
    QFileDialog not started in needs dir, hi started in /home

    filePaths = QFileDialog.getOpenFileNames(self, "Open npy", "./dbFiles", "npy files (*.npy )")[0]
    

    How this fix ?

    jsulmJ 1 Reply Last reply
    0
    • M Mihaill

      Hi!
      I use Ubuntu 20.
      QFileDialog not started in needs dir, hi started in /home

      filePaths = QFileDialog.getOpenFileNames(self, "Open npy", "./dbFiles", "npy files (*.npy )")[0]
      

      How this fix ?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Mihaill said in QFileDialog not started in needs dir:

      "./dbFiles"

      You're using relative path. Relative paths are relative to current working directory.
      Try to pass an absolute path instead.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • M Offline
        M Offline
        Mihaill
        wrote on last edited by
        #3

        @jsulm said in QFileDialog not started in needs dir:

        Try to pass an absolute path instead.

        I try this, but this too not work:

        filePaths = QFileDialog.getOpenFileNames(self, "Open npy", "/home/owner/PythonProjects/add3DImagesInDb/dbFiles", "npy files (*.npy )")[0]
        
        JonBJ 1 Reply Last reply
        0
        • M Mihaill

          @jsulm said in QFileDialog not started in needs dir:

          Try to pass an absolute path instead.

          I try this, but this too not work:

          filePaths = QFileDialog.getOpenFileNames(self, "Open npy", "/home/owner/PythonProjects/add3DImagesInDb/dbFiles", "npy files (*.npy )")[0]
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @Mihaill
          "Not work" meaning "does not start in /home/owner/PythonProjects/add3DImagesInDb/dbFiles"?
          Before posting this you would have made sure that /home/owner/PythonProjects/add3DImagesInDb/dbFiles really does exist (case-sensitive) as a directory, wouldn't you....? E.g. your username is owner, is it?
          Open a terminal and show the output from: ls -ld /home/owner/PythonProjects/add3DImagesInDb/dbFiles

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mihaill
            wrote on last edited by
            #5

            Dir is exist /home/owner/PythonProjects/add3DImagesInDb/dbFiles
            This command works

            cd /home/owner/PythonProjects/add3DImagesInDb/dbFiles
            
            

            This code open dialog in /home

            filePaths = QFileDialog.getOpenFileNames(self, "Open npy", "/home/owner/PythonProjects/add3DImagesInDb/dbFiles", "npy files (*.npy )")[0]
            
            JonBJ 1 Reply Last reply
            0
            • M Mihaill

              Dir is exist /home/owner/PythonProjects/add3DImagesInDb/dbFiles
              This command works

              cd /home/owner/PythonProjects/add3DImagesInDb/dbFiles
              
              

              This code open dialog in /home

              filePaths = QFileDialog.getOpenFileNames(self, "Open npy", "/home/owner/PythonProjects/add3DImagesInDb/dbFiles", "npy files (*.npy )")[0]
              
              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @Mihaill
              Then I don't know why it does not work for you but does for anyone else.
              Try replacing "/home/owner/PythonProjects/add3DImagesInDb/dbFiles" by "/" and then by "/tmp". Where does it show for each of these?
              What version of Qt are you using?

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Mihaill
                wrote on last edited by
                #7

                I use pyqt 5.15
                If do "/" and "/tmp", then open /home

                JonBJ 1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Hi,

                  How did you install PyQt ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    Mihaill
                    wrote on last edited by Mihaill
                    #9

                    I use pycharm for installing

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      In a virtual environment ?
                      Can you test your application outside of PyCharm ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • M Mihaill

                        I use pyqt 5.15
                        If do "/" and "/tmp", then open /home

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

                        @Mihaill
                        Also what does print(QDir("/home/owner/PythonProjects/add3DImagesInDb/dbFiles").exists()) run from your program in its PyCharm/virtual environment tell you?

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          Mihaill
                          wrote on last edited by
                          #12

                          @JonB said in QFileDialog not started in needs dir:

                          print(QDir("/home/owner/PythonProjects/add3DImagesInDb/dbFiles").exists())

                          It's return True

                          JonBJ 1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            Mihaill
                            wrote on last edited by
                            #13

                            @SGaist said in QFileDialog not started in needs dir:

                            In a virtual environment ?
                            Can you test your application outside of PyCharm ?

                            Linux work on laptop.
                            If I run app with outside , then open /home in QDialog

                            1 Reply Last reply
                            0
                            • M Mihaill

                              @JonB said in QFileDialog not started in needs dir:

                              print(QDir("/home/owner/PythonProjects/add3DImagesInDb/dbFiles").exists())

                              It's return True

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

                              @Mihaill said in QFileDialog not started in needs dir:

                              print(QDir("/home/owner/PythonProjects/add3DImagesInDb/dbFiles").exists())

                              It's return True

                              @Mihaill said in QFileDialog not started in needs dir:

                              If I run app with outside , then open /home in QDialog

                              So you seem to be saying it starts in /home and ignores your directory parameter in all cases.

                              In that case I give up, works fine for me in Ubuntu 20. Though I only use C++. You have not said which Qt Python you are using, maybe try the opposite one, maybe it's a bug in whichever one you use.

                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                Please provide a minimal script that shows this behaviour.

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                0
                                • M Offline
                                  M Offline
                                  Mihaill
                                  wrote on last edited by
                                  #16

                                  @SGaist said in QFileDialog not started in needs dir:

                                  Please provide a minimal script that shows this behaviour.

                                  import sys
                                  from PyQt5.QtWidgets import QApplication, QWidget, QFileDialog
                                  import requests
                                  
                                  if __name__ == '__main__':
                                  
                                      app = QApplication(sys.argv)
                                      w = QWidget()
                                      filePaths = QFileDialog.getOpenFileNames(w, "Open npy", "/home/owner/PythonProjects/add3DImagesInDb/dbFiles", "npy files (*.npy )")[0]
                                  
                                      sys.exit(app.exec_())
                                  
                                  1 Reply Last reply
                                  0
                                  • SGaistS Offline
                                    SGaistS Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #17

                                    Using a path that exists on my machine, no problem, it opens correctly.

                                    Can you share the exact version of the package you installed ?

                                    Interested in AI ? www.idiap.ch
                                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    1 Reply Last reply
                                    0
                                    • M Offline
                                      M Offline
                                      Mihaill
                                      wrote on last edited by
                                      #18

                                      Снимок экрана от 2022-04-01 09-09-06.png

                                      JonBJ 1 Reply Last reply
                                      0
                                      • M Mihaill

                                        Снимок экрана от 2022-04-01 09-09-06.png

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

                                        @Mihaill
                                        A couple of suggestions at this point.

                                        • Can you try some of the other static functions than getOpenFileNames(). There are getOpenFileName(), getSaveFileName() and getExistingDirectory(). Do any of these respect your requested starting directory or do they all use /home regardless?

                                        • You should be able to specify options. I'd like you to try DontUseNativeDialog in case that is relevant. I think it would be something like:

                                        QFileDialog.getOpenFileName(w, "...", "/tmp", "...", options=QFileDialog.DontUseNativeDialog)
                                        
                                        • Instead of the static functions, try one of the ones which use a QFileDialog instance. Something like:
                                        fd = QFileDialog(w)
                                        fd.setDirectory("/tmp")
                                        fd.exec()
                                        
                                        1 Reply Last reply
                                        0
                                        • C Offline
                                          C Offline
                                          cjw25
                                          wrote on last edited by
                                          #20

                                          Sorry to re-ignite this. But I am having the exact issue. Our program is C++ and we cross build Redhat, MacOS, and msys2/mingw. Using Qt 5.12 through 5.15 (whatever the latest packages are). I am also using the static function getOpenFileName().

                                          MacOS and mingw work just fine. On both CentOS 8 and Alma 9, the native QFileDialog defaults to "Recents". I do specify a fully qualified path. I now have a #ifdef linux that sets options to DontUseNativeDialog. This works fine. But the compilers on the other OSs are complaining that passing in zero is deprecated. So I am out looking for a solution....and if nothing else, to say that the OP is not delusional.

                                          JonBJ 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