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 keep percent encoded spaces in an url?
Forum Updated to NodeBB v4.3 + New Features

How to keep percent encoded spaces in an url?

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

    Hi,

    I'm facing an issue when I try to open a site using QDesktopServices::openUrl(). The url I have in QString contains a list of space separated values in the query part. I replaced them with the percent encoded value (%20) already, but when this string us passed to QUrl it automatically changes them back to spaces.
    Why? How can I disable this unwanted behaviour?
    I would expect if I pass a string with spaces it encodes them to percent encoded values and not this opposit.
    Thanks and regards,
    Laszlo

    jsulmJ JonBJ 2 Replies Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      I don't understand the problem here - what exactly does your external program need? I don't see any need to percent encode the space for an argument of a programm so why do you need it?

      B Offline
      B Offline
      Blaise70
      wrote on last edited by
      #7

      @Christian-Ehrlicher and All
      Hi,
      I got an error message that the query is incorret. So my first understanding was that it requires encoded spaces. I finally realised that ther was a typo. So it works now with not encoded spaces. The missleading error message directed me into completley wrong direction.
      Sorry for eating up your time and thank you all for helping me.
      I really appreciate it.
      Thanks and regards,
      Laszlo

      1 Reply Last reply
      1
      • B Blaise70

        Hi,

        I'm facing an issue when I try to open a site using QDesktopServices::openUrl(). The url I have in QString contains a list of space separated values in the query part. I replaced them with the percent encoded value (%20) already, but when this string us passed to QUrl it automatically changes them back to spaces.
        Why? How can I disable this unwanted behaviour?
        I would expect if I pass a string with spaces it encodes them to percent encoded values and not this opposit.
        Thanks and regards,
        Laszlo

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @Blaise70 Maybe you need to use QUrl::DecodedMode, see https://doc.qt.io/qt-6/qurl.html#ParsingMode-enum

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        B 1 Reply Last reply
        0
        • B Blaise70

          Hi,

          I'm facing an issue when I try to open a site using QDesktopServices::openUrl(). The url I have in QString contains a list of space separated values in the query part. I replaced them with the percent encoded value (%20) already, but when this string us passed to QUrl it automatically changes them back to spaces.
          Why? How can I disable this unwanted behaviour?
          I would expect if I pass a string with spaces it encodes them to percent encoded values and not this opposit.
          Thanks and regards,
          Laszlo

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

          @Blaise70
          I don't think you are supposed to care, space and %20 are the same character. But I see there is enum QUrl::ComponentFormattingOption

          QUrl::EncodeSpaces 0x100000 Leave space characters in their encoded form ("%20").

          B 1 Reply Last reply
          1
          • jsulmJ jsulm

            @Blaise70 Maybe you need to use QUrl::DecodedMode, see https://doc.qt.io/qt-6/qurl.html#ParsingMode-enum

            B Offline
            B Offline
            Blaise70
            wrote on last edited by
            #4

            @jsulm
            Thanks for your kins answer. Yes, I tried and according to the help it should keep spaces in both form, but somehow it always converts %20 back to ' '.
            Anyway, I'll keep trying.
            Br, Laszlo

            1 Reply Last reply
            0
            • JonBJ JonB

              @Blaise70
              I don't think you are supposed to care, space and %20 are the same character. But I see there is enum QUrl::ComponentFormattingOption

              QUrl::EncodeSpaces 0x100000 Leave space characters in their encoded form ("%20").

              B Offline
              B Offline
              Blaise70
              wrote on last edited by
              #5

              @JonB
              Thanks for your kind answer.
              Yes, I looked at it, but unfortunatelt all the functions accepting this type are returning QString. Like query which seems converting the query part of the url into a Qstring. setQuery seems OK except it uses the ParsingMode enum and even though TolarentMode should work according to the help, it seems not.
              I'll keep trying,
              Thanks and regards,
              Laszlo

              Christian EhrlicherC 1 Reply Last reply
              0
              • B Blaise70

                @JonB
                Thanks for your kind answer.
                Yes, I looked at it, but unfortunatelt all the functions accepting this type are returning QString. Like query which seems converting the query part of the url into a Qstring. setQuery seems OK except it uses the ParsingMode enum and even though TolarentMode should work according to the help, it seems not.
                I'll keep trying,
                Thanks and regards,
                Laszlo

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

                I don't understand the problem here - what exactly does your external program need? I don't see any need to percent encode the space for an argument of a programm so why do you need it?

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

                B 1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

                  I don't understand the problem here - what exactly does your external program need? I don't see any need to percent encode the space for an argument of a programm so why do you need it?

                  B Offline
                  B Offline
                  Blaise70
                  wrote on last edited by
                  #7

                  @Christian-Ehrlicher and All
                  Hi,
                  I got an error message that the query is incorret. So my first understanding was that it requires encoded spaces. I finally realised that ther was a typo. So it works now with not encoded spaces. The missleading error message directed me into completley wrong direction.
                  Sorry for eating up your time and thank you all for helping me.
                  I really appreciate it.
                  Thanks and regards,
                  Laszlo

                  1 Reply Last reply
                  1
                  • B Blaise70 has marked this topic as solved on

                  • Login

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