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. QDir::exists() returns false while directory exists
Forum Updated to NodeBB v4.3 + New Features

QDir::exists() returns false while directory exists

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 5 Posters 339 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.
  • A Offline
    A Offline
    Aleksey Asensus
    wrote on last edited by
    #1

    Similar issue to that one:
    https://forum.qt.io/topic/124795/issues-with-qtdir-exist

    While Qt doc says
    https://doc.qt.io/qt-6/qdir.html#examples
    to check dir existence do:

        QDir path(myPath);
        return path.exists() && path.isReadable() 
    

    both functions return false while dir exists and readable (selected by QML FolderDialog). Qt 6.8.2, Ubuntu 22.04. What the problem could be?! Qt bug? How to solve?

    1 Reply Last reply
    0
    • Aleksey_KA Aleksey_K

      @J-Hilk said in QDir::exists() returns false while directory exists:

      Folrderdialog gives you a QUrl not a path that QDir would accept.
      How to you convert it ?

      I have not converted it, thought QDir should understand QUrl. So QDir::toNativeSeparators(QUrl(myPath).toLocalFile()) works - thanks!

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

      @Aleksey_K
      No need to call QDir::toNativeSeparators() here, the QUrl(myPath).toLocalFile() turns it into a Qt-platform-agnostic /-type path, which is all Qt file routines are happy dealing with. You only need toNativeSeparators() if you need to do something "external" which demands a native, real OS e.g. \-type path, such as passing it to an OS command or a native OS system call. Just so you know.

      1 Reply Last reply
      3
      • J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #2

        Folrderdialog gives you a QUrl not a path that QDir would accept.
        How to you convert it ?


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        Aleksey_KA 1 Reply Last reply
        3
        • J.HilkJ J.Hilk

          Folrderdialog gives you a QUrl not a path that QDir would accept.
          How to you convert it ?

          Aleksey_KA Offline
          Aleksey_KA Offline
          Aleksey_K
          wrote on last edited by
          #3

          @J-Hilk said in QDir::exists() returns false while directory exists:

          Folrderdialog gives you a QUrl not a path that QDir would accept.
          How to you convert it ?

          I have not converted it, thought QDir should understand QUrl. So QDir::toNativeSeparators(QUrl(myPath).toLocalFile()) works - thanks!

          JonBJ Christian EhrlicherC 2 Replies Last reply
          1
          • Aleksey_KA Offline
            Aleksey_KA Offline
            Aleksey_K
            wrote on last edited by
            #4
            This post is deleted!
            1 Reply Last reply
            0
            • A Aleksey Asensus has marked this topic as solved on
            • Aleksey_KA Aleksey_K

              @J-Hilk said in QDir::exists() returns false while directory exists:

              Folrderdialog gives you a QUrl not a path that QDir would accept.
              How to you convert it ?

              I have not converted it, thought QDir should understand QUrl. So QDir::toNativeSeparators(QUrl(myPath).toLocalFile()) works - thanks!

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

              @Aleksey_K
              No need to call QDir::toNativeSeparators() here, the QUrl(myPath).toLocalFile() turns it into a Qt-platform-agnostic /-type path, which is all Qt file routines are happy dealing with. You only need toNativeSeparators() if you need to do something "external" which demands a native, real OS e.g. \-type path, such as passing it to an OS command or a native OS system call. Just so you know.

              1 Reply Last reply
              3
              • A Aleksey Asensus has marked this topic as solved on
              • Aleksey_KA Aleksey_K

                @J-Hilk said in QDir::exists() returns false while directory exists:

                Folrderdialog gives you a QUrl not a path that QDir would accept.
                How to you convert it ?

                I have not converted it, thought QDir should understand QUrl. So QDir::toNativeSeparators(QUrl(myPath).toLocalFile()) works - thanks!

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

                @Aleksey_K said in QDir::exists() returns false while directory exists:

                thought QDir should understand QUrl.

                Where did you read this? A local directory is something totally different than an url...

                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