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. Getting invalid path from file dialog

Getting invalid path from file dialog

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 628 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.
  • C Offline
    C Offline
    Creaperdown
    wrote on 23 Jul 2023, 08:01 last edited by
    #1

    Hey, I'm on windows and paths I get from qml file dialogs are in the format "File:///C/User/..." (notice the 3 /). When converting it to a QUrl and then calling path() on it, it gives me an invalid path like "/C/User/...", does anyone have an idea how to correct approach to do this would be?

    J 1 Reply Last reply 23 Jul 2023, 08:36
    0
    • C Creaperdown
      23 Jul 2023, 10:37

      @JonB Apologies. I have multiple problems with paths across my project while porting it to windows. I have fixed the previous problem, but in the case just described, toLocalFile() does not work.

      J Offline
      J Offline
      JonB
      wrote on 23 Jul 2023, 10:47 last edited by
      #8

      @Creaperdown
      Start by testing with literals what will work. I expected file:///C:/Users/... to work. You have now introduced file://C:/Users/....

      C 1 Reply Last reply 23 Jul 2023, 15:59
      1
      • C Creaperdown
        23 Jul 2023, 08:01

        Hey, I'm on windows and paths I get from qml file dialogs are in the format "File:///C/User/..." (notice the 3 /). When converting it to a QUrl and then calling path() on it, it gives me an invalid path like "/C/User/...", does anyone have an idea how to correct approach to do this would be?

        J Offline
        J Offline
        JonB
        wrote on 23 Jul 2023, 08:36 last edited by JonB
        #2

        @Creaperdown
        Are you wanting a local file path from the Url? What does QUrl::toLocalFile() return?

        The 3 /s are expected. But I thought there would be an extra : for the drive: file:///C:/User/....

        C 1 Reply Last reply 23 Jul 2023, 08:54
        0
        • J JonB
          23 Jul 2023, 08:36

          @Creaperdown
          Are you wanting a local file path from the Url? What does QUrl::toLocalFile() return?

          The 3 /s are expected. But I thought there would be an extra : for the drive: file:///C:/User/....

          C Offline
          C Offline
          Creaperdown
          wrote on 23 Jul 2023, 08:54 last edited by
          #3

          @JonB toLocalFile() seems to return the correct thing. What exactly is the difference between path() and toLocalFile()? I have checked the docs but I do not get the exact difference, and when I should use what.

          J 1 Reply Last reply 23 Jul 2023, 10:09
          0
          • C Creaperdown
            23 Jul 2023, 08:54

            @JonB toLocalFile() seems to return the correct thing. What exactly is the difference between path() and toLocalFile()? I have checked the docs but I do not get the exact difference, and when I should use what.

            J Offline
            J Offline
            JonB
            wrote on 23 Jul 2023, 10:09 last edited by JonB
            #4

            @Creaperdown
            I think you will find that QUrl::path() returns a Url path (probably with schema removed), not a (local) file path which you seemed to expect it to do? localPath() converts from Url to file path.

            C 1 Reply Last reply 23 Jul 2023, 10:30
            0
            • J JonB
              23 Jul 2023, 10:09

              @Creaperdown
              I think you will find that QUrl::path() returns a Url path (probably with schema removed), not a (local) file path which you seemed to expect it to do? localPath() converts from Url to file path.

              C Offline
              C Offline
              Creaperdown
              wrote on 23 Jul 2023, 10:30 last edited by
              #5

              @JonB I don't get it. I have a string like file://C:/Users/prtnp/Librum/build/librum_localLibraries/13824929713553088125/ac17af33-67b7-4b57-a6eb-e7bb69cc0d3f.pdf and I simply want the actual path to it, with no scheme.
              toLocalFile is gicing me //c/Users/prtnp/Librum/build/librum_localLibraries/13824929713553088125/ac17af33-67b7-4b57-a6eb-e7bb69cc0d3f.PDF 1.5 for some reason and path() gives me /Users/prtnp/Librum/build/librum_localLibraries/13824929713553088125/ac17af33-67b7-4b57-a6eb-e7bb69cc0d3f.PDF 1.5.

              What can I do to just get the path to my file: C:/Users/...?

              J 1 Reply Last reply 23 Jul 2023, 10:35
              0
              • C Creaperdown
                23 Jul 2023, 10:30

                @JonB I don't get it. I have a string like file://C:/Users/prtnp/Librum/build/librum_localLibraries/13824929713553088125/ac17af33-67b7-4b57-a6eb-e7bb69cc0d3f.pdf and I simply want the actual path to it, with no scheme.
                toLocalFile is gicing me //c/Users/prtnp/Librum/build/librum_localLibraries/13824929713553088125/ac17af33-67b7-4b57-a6eb-e7bb69cc0d3f.PDF 1.5 for some reason and path() gives me /Users/prtnp/Librum/build/librum_localLibraries/13824929713553088125/ac17af33-67b7-4b57-a6eb-e7bb69cc0d3f.PDF 1.5.

                What can I do to just get the path to my file: C:/Users/...?

                J Offline
                J Offline
                JonB
                wrote on 23 Jul 2023, 10:35 last edited by
                #6

                @Creaperdown said in Getting invalid path from file dialog:

                I don't get it. I have a string like file://C:/Users/prtnp/Librum/build/librum_localLibraries/13824929713553088125/ac17af33-67b7-4b57-a6eb-e7bb69cc0d3f.pdf

                Can you please start being consistent in what you report, since it is critical. You begin by telling us format "File:///C/User/..." (notice the 3 /). . Now you show it with 2 //s. You also said toLocalFile() seems to return the correct thing. Now you say it does not.

                C 1 Reply Last reply 23 Jul 2023, 10:37
                0
                • J JonB
                  23 Jul 2023, 10:35

                  @Creaperdown said in Getting invalid path from file dialog:

                  I don't get it. I have a string like file://C:/Users/prtnp/Librum/build/librum_localLibraries/13824929713553088125/ac17af33-67b7-4b57-a6eb-e7bb69cc0d3f.pdf

                  Can you please start being consistent in what you report, since it is critical. You begin by telling us format "File:///C/User/..." (notice the 3 /). . Now you show it with 2 //s. You also said toLocalFile() seems to return the correct thing. Now you say it does not.

                  C Offline
                  C Offline
                  Creaperdown
                  wrote on 23 Jul 2023, 10:37 last edited by
                  #7

                  @JonB Apologies. I have multiple problems with paths across my project while porting it to windows. I have fixed the previous problem, but in the case just described, toLocalFile() does not work.

                  J 1 Reply Last reply 23 Jul 2023, 10:47
                  0
                  • C Creaperdown
                    23 Jul 2023, 10:37

                    @JonB Apologies. I have multiple problems with paths across my project while porting it to windows. I have fixed the previous problem, but in the case just described, toLocalFile() does not work.

                    J Offline
                    J Offline
                    JonB
                    wrote on 23 Jul 2023, 10:47 last edited by
                    #8

                    @Creaperdown
                    Start by testing with literals what will work. I expected file:///C:/Users/... to work. You have now introduced file://C:/Users/....

                    C 1 Reply Last reply 23 Jul 2023, 15:59
                    1
                    • J JonB
                      23 Jul 2023, 10:47

                      @Creaperdown
                      Start by testing with literals what will work. I expected file:///C:/Users/... to work. You have now introduced file://C:/Users/....

                      C Offline
                      C Offline
                      Creaperdown
                      wrote on 23 Jul 2023, 15:59 last edited by
                      #9

                      @JonB Thank you. I have gone over it again, realized that all the paths I get from Qml are in the format "file:///" and that it only accepts paths with in the format "file:///", then I have found that toLocalPath seems to convert it to what I want and I changed it accordingly

                      J 1 Reply Last reply 23 Jul 2023, 16:14
                      0
                      • C Creaperdown has marked this topic as solved on 23 Jul 2023, 15:59
                      • C Creaperdown
                        23 Jul 2023, 15:59

                        @JonB Thank you. I have gone over it again, realized that all the paths I get from Qml are in the format "file:///" and that it only accepts paths with in the format "file:///", then I have found that toLocalPath seems to convert it to what I want and I changed it accordingly

                        J Offline
                        J Offline
                        JonB
                        wrote on 23 Jul 2023, 16:14 last edited by
                        #10

                        @Creaperdown
                        I don't use QML, but if file dialog returns Urls of form file:// but it needs to be file:/// that would be strange/unhelpful. But I don't know.

                        C 1 Reply Last reply 23 Jul 2023, 16:18
                        0
                        • J JonB
                          23 Jul 2023, 16:14

                          @Creaperdown
                          I don't use QML, but if file dialog returns Urls of form file:// but it needs to be file:/// that would be strange/unhelpful. But I don't know.

                          C Offline
                          C Offline
                          Christian Ehrlicher
                          Lifetime Qt Champion
                          wrote on 23 Jul 2023, 16:18 last edited by
                          #11

                          @JonB It would be a bug since the schema is file:// (two /) and the path is /foo/bar. And since the path must always start with a / it's file:///C:/foo/bar - everything else is wrong.

                          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

                          2/11

                          23 Jul 2023, 08:36

                          topic:navigator.unread, 9
                          • Login

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