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. Question about passing invalid directory path to QFileDialog::getExistingDirectory()
Forum Updated to NodeBB v4.3 + New Features

Question about passing invalid directory path to QFileDialog::getExistingDirectory()

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 580 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.
  • W Offline
    W Offline
    walle19
    wrote on last edited by
    #1

    Hi All,
    What happens when passing the QFileDialog::getExistingDirectory() a illegal path?

    More specific passing the third argument a path to directory that doesn't exist:

    QString QFileDialog::getExistingDirectory(QWidget * parent = 0, const QString & caption = QString(), const QString & dir = QString(), Options options = ShowDirsOnly);

    from the qt documentation

    What will be the return value in this case?

    kshegunovK 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #4

      @walle19 said in Question about passing invalid directory path to QFileDialog::getExistingDirectory():

      How does it choose where to open at if the third argument is an invalid directory path?

      "The dialog's working directory is set to dir, and the caption is set to caption. Either of these may be an empty string in which case the current directory and a default caption will be used respectively."

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      W 1 Reply Last reply
      3
      • W walle19

        Hi All,
        What happens when passing the QFileDialog::getExistingDirectory() a illegal path?

        More specific passing the third argument a path to directory that doesn't exist:

        QString QFileDialog::getExistingDirectory(QWidget * parent = 0, const QString & caption = QString(), const QString & dir = QString(), Options options = ShowDirsOnly);

        from the qt documentation

        What will be the return value in this case?

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by kshegunov
        #2

        @walle19 said in Question about passing invalid directory path to QFileDialog::getExistingDirectory():

        What will be the return value in this case?

        The return value is going to be the directory you will have selected from the file dialog. If you discarded the dialog (i.e. didn't select anything), then it's an empty string.

        Read and abide by the Qt Code of Conduct

        W 1 Reply Last reply
        1
        • kshegunovK kshegunov

          @walle19 said in Question about passing invalid directory path to QFileDialog::getExistingDirectory():

          What will be the return value in this case?

          The return value is going to be the directory you will have selected from the file dialog. If you discarded the dialog (i.e. didn't select anything), then it's an empty string.

          W Offline
          W Offline
          walle19
          wrote on last edited by
          #3

          @kshegunov I understand.
          So where is the file dialog going to open at ?
          If I pass the third argument a valid directory path then it will open on the valid directory.
          How does it choose where to open at if the third argument is an invalid directory path?

          JonBJ 1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @walle19 said in Question about passing invalid directory path to QFileDialog::getExistingDirectory():

            How does it choose where to open at if the third argument is an invalid directory path?

            "The dialog's working directory is set to dir, and the caption is set to caption. Either of these may be an empty string in which case the current directory and a default caption will be used respectively."

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            W 1 Reply Last reply
            3
            • W walle19

              @kshegunov I understand.
              So where is the file dialog going to open at ?
              If I pass the third argument a valid directory path then it will open on the valid directory.
              How does it choose where to open at if the third argument is an invalid directory path?

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by
              #5

              @walle19
              In addition to @Christian-Ehrlicher's suggestion that it will use "the current directory" when non-existent path, did you actually quickly try that and see where it opened for you?

              1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                @walle19 said in Question about passing invalid directory path to QFileDialog::getExistingDirectory():

                How does it choose where to open at if the third argument is an invalid directory path?

                "The dialog's working directory is set to dir, and the caption is set to caption. Either of these may be an empty string in which case the current directory and a default caption will be used respectively."

                W Offline
                W Offline
                walle19
                wrote on last edited by
                #6

                @Christian-Ehrlicher I havn't used an empty string. The documentation doesn't say anything about invalid string / path

                Christian EhrlicherC 1 Reply Last reply
                0
                • W walle19

                  @Christian-Ehrlicher I havn't used an empty string. The documentation doesn't say anything about invalid string / path

                  Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  @walle19 Then try it out. Don't see why it should behave different for non-existing and empty directory since an empty directory is also non-existent...

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  1

                  • Login

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