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
Forum Updated to NodeBB v4.3 + New Features

Getting invalid path from file dialog

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 809 Views 2 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.
  • C Creaperdown

    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?

    JonBJ Online
    JonBJ Online
    JonB
    wrote on 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
    0
    • JonBJ JonB

      @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 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.

      JonBJ 1 Reply Last reply
      0
      • C Creaperdown

        @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.

        JonBJ Online
        JonBJ Online
        JonB
        wrote on 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
        0
        • JonBJ JonB

          @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 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/...?

          JonBJ 1 Reply Last reply
          0
          • C Creaperdown

            @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/...?

            JonBJ Online
            JonBJ Online
            JonB
            wrote on 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
            0
            • JonBJ JonB

              @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 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.

              JonBJ 1 Reply Last reply
              0
              • C Creaperdown

                @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.

                JonBJ Online
                JonBJ Online
                JonB
                wrote on 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
                1
                • JonBJ JonB

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

                  JonBJ 1 Reply Last reply
                  0
                  • C Creaperdown has marked this topic as solved on
                  • C Creaperdown

                    @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

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on 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.

                    Christian EhrlicherC 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @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.

                      Christian EhrlicherC Offline
                      Christian EhrlicherC Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on 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

                      • Login

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