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. How to handle QUrl with spaces
Forum Update on Monday, May 27th 2025

How to handle QUrl with spaces

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 5 Posters 1.6k 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.
  • A Abhi_Varma

    @Christian-Ehrlicher I'm sharing a file to a device via a server. For that I created a Qurl object set the path, Scheme, Host, Port for the Url. Then I created a QNetworkRequest object for the url and calling a post method of QNetworkAccessManager. Since the path has spaces in it the server cannot find it and I'm not getting a response

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

    @Abhi_Varma said in How to handle QUrl with spaces:

    Since the path has spaces in it the server cannot find it and I'm not getting a response

    I doubt that this is the problem on the Qt side. Please show how/what you pass because 'Then I created a QNetworkRequest object for the url ' does not tell u what/how you're doing it. Do you pass a string? A json object, ...? Please show some code!

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

    A 1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      @Abhi_Varma said in How to handle QUrl with spaces:

      Since the path has spaces in it the server cannot find it and I'm not getting a response

      I doubt that this is the problem on the Qt side. Please show how/what you pass because 'Then I created a QNetworkRequest object for the url ' does not tell u what/how you're doing it. Do you pass a string? A json object, ...? Please show some code!

      A Offline
      A Offline
      Abhi_Varma
      wrote on last edited by
      #7

      @Christian-Ehrlicher I have a function to which file path is passed. In that function I do something like
      Say filepath = "C:\Desktop\My files\file.csv"

      QUrl url(ServerApiPath + "/" + filepath);
      url.setSchema("http");
      url.setHost("127.0.0.1");
      url.setPort("8006");
      qDebug() <<url;

      After that I create the some data and then the network request object... But when url is printed on the terminal

      QUrl("ServerApiPath/C:\Desktop\My file\file.csv")

      In this upto "My" it's considering as url and its highlighted as blue and not considering rest of the string(" files\file.csv") due to that space. My doubt is how to make QUrl consider the entire filepath string with space.

      I have tried the above thing with the following path it works fine if my folder name doesn't have a space.
      C:\Desktop\Myfiles\file.csv

      1 Reply Last reply
      0
      • Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #8

        So you create an url which contains a path which is in fact a local file? I don't understand what this should do or why this is needed at all. What strange api is this?

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

        A 1 Reply Last reply
        1
        • Christian EhrlicherC Christian Ehrlicher

          So you create an url which contains a path which is in fact a local file? I don't understand what this should do or why this is needed at all. What strange api is this?

          A Offline
          A Offline
          Abhi_Varma
          wrote on last edited by Abhi_Varma
          #9

          @Christian-Ehrlicher it really a intermidiate server between app and device. It launches along with the app and used to communicate with devices via LAN.
          But still how handle a path with a space in url. That is the issue not the server api

          1 Reply Last reply
          0
          • Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #10

            You still did not show us how you send the data...

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

            A 1 Reply Last reply
            1
            • Christian EhrlicherC Christian Ehrlicher

              You still did not show us how you send the data...

              A Offline
              A Offline
              Abhi_Varma
              wrote on last edited by
              #11

              @Christian-Ehrlicher I can't share the code as it's a project of the company I'm working for. It's confidential. But what does that have to do I have Shared the basic issue I'm facing with QUrl that it's not considering the entire path if there are any spaces in the path. Isn't there way for this in qt to handle like by setting a mode or something

              1 Reply Last reply
              0
              • Christian EhrlicherC Online
                Christian EhrlicherC Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #12

                If you can't show us three lines on how you pass the QUrl as request to a QNetworkmanager we can't help either.

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

                A 1 Reply Last reply
                2
                • Christian EhrlicherC Christian Ehrlicher

                  If you can't show us three lines on how you pass the QUrl as request to a QNetworkmanager we can't help either.

                  A Offline
                  A Offline
                  Abhi_Varma
                  wrote on last edited by
                  #13

                  @Christian-Ehrlicher
                  QUrl url(ServerApiPath + "/" + filepath);
                  url.setSchema("http");
                  url.setHost("127.0.0.1");
                  url.setPort("8006");
                  qDebug() <<url;

                  Qbytearray data;
                  "Add some string say hello world text to qbytearray"

                  QNetworkreqyest request(url)
                  (QNetworkAccessManager Object).post(request, data)

                  I'm doing this becoz we r using the concept of rest calls. Here there is no use for data for my scenario, but passing some qbytearray obj just to see if it works and also the post method needs a second argument.

                  Note:The above code is working if the file path doens't have a space in it

                  1 Reply Last reply
                  0
                  • Christian EhrlicherC Online
                    Christian EhrlicherC Online
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #14

                    Since QNAM properly encodes spaces I don't see where there should be an error on the Qt side.

                    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
                    • JKSHJ Offline
                      JKSHJ Offline
                      JKSH
                      Moderators
                      wrote on last edited by
                      #15

                      @Abhi_Varma Have you checked if the URL is valid? What do you get when you call:

                      qDebug() << url.isValid();
                      qDebug() << url.errorString();
                      

                      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                      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