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. QUrl setPath with the symbol '?'

QUrl setPath with the symbol '?'

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 4.0k 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.
  • AlexorleonA Offline
    AlexorleonA Offline
    Alexorleon
    wrote on last edited by
    #1

    Hi.
    When I use setPath("/Streaming/channels/1/picture?snapShotImageType=JPEG"), the output is a

    QUrl("http://admin@192.168.1.64/Streaming/channels/1/picture%3FsnapShotImageType=JPEG")
    

    Symbol was replaced
    ? -> %3F

    I do not need it. I tried using QUrl::ParsingMode, but it did not help.
    How to leave this character?

    K 1 Reply Last reply
    0
    • AlexorleonA Alexorleon

      Hi.
      When I use setPath("/Streaming/channels/1/picture?snapShotImageType=JPEG"), the output is a

      QUrl("http://admin@192.168.1.64/Streaming/channels/1/picture%3FsnapShotImageType=JPEG")
      

      Symbol was replaced
      ? -> %3F

      I do not need it. I tried using QUrl::ParsingMode, but it did not help.
      How to leave this character?

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @Alexorleon

      I think it should be that way. Check out this and the corrsponding rfc , because it is the way as sent.

      In case you want to change it you can use QString::replace

      Vote the answer(s) that helped you to solve your issue(s)

      AlexorleonA 1 Reply Last reply
      1
      • K koahnig

        @Alexorleon

        I think it should be that way. Check out this and the corrsponding rfc , because it is the way as sent.

        In case you want to change it you can use QString::replace

        AlexorleonA Offline
        AlexorleonA Offline
        Alexorleon
        wrote on last edited by
        #3

        @koahnig thanks, it's useful article.
        I have not found how to disable the conversion of characters, so I decided to create an address by QString.

        1 Reply Last reply
        0
        • Paul ColbyP Offline
          Paul ColbyP Offline
          Paul Colby
          wrote on last edited by Paul Colby
          #4

          Hi @Alexorleon,

          The %3F sequence was not replaced during parsing, but during presentation.

          Consider:

              QUrl url1(QLatin1Literal("http://admin@192.168.1.64/Streaming/channels/1/picture%3FsnapShotImageType=JPEG"));
              qDebug() << url1.path();
              qDebug() << url1.path(QUrl::FullyEncoded);
              qDebug() << url1.query();
          
              QUrl url2(QLatin1Literal("http://admin@192.168.1.64/Streaming/channels/1/picture?snapShotImageType=JPEG"));
              qDebug() << url2.path();
              qDebug() << url2.path(QUrl::FullyEncoded);
              qDebug() << url2.query();
          

          The output is:

          "/Streaming/channels/1/picture?snapShotImageType=JPEG"
          "/Streaming/channels/1/picture%3FsnapShotImageType=JPEG"
          ""
          "/Streaming/channels/1/picture"
          "/Streaming/channels/1/picture"
          "snapShotImageType=JPEG"
          

          Which is exactly what I'd expect (given that the default argument to QUrl::path is QUrl::FullyDecoded).

          Edit:

          Just adding an example that's a little closer to your original post:

              QUrl url("http://admin@192.168.1.64");
              url.setPath("/Streaming/channels/1/picture?snapShotImageType=JPEG");
              qDebug() << url.toString(QUrl::FullyEncoded);
          

          Output:

          "http://admin@192.168.1.64/Streaming/channels/1/picture%3FsnapShotImageType=JPEG"
          

          Cheers.

          AlexorleonA 1 Reply Last reply
          2
          • Paul ColbyP Paul Colby

            Hi @Alexorleon,

            The %3F sequence was not replaced during parsing, but during presentation.

            Consider:

                QUrl url1(QLatin1Literal("http://admin@192.168.1.64/Streaming/channels/1/picture%3FsnapShotImageType=JPEG"));
                qDebug() << url1.path();
                qDebug() << url1.path(QUrl::FullyEncoded);
                qDebug() << url1.query();
            
                QUrl url2(QLatin1Literal("http://admin@192.168.1.64/Streaming/channels/1/picture?snapShotImageType=JPEG"));
                qDebug() << url2.path();
                qDebug() << url2.path(QUrl::FullyEncoded);
                qDebug() << url2.query();
            

            The output is:

            "/Streaming/channels/1/picture?snapShotImageType=JPEG"
            "/Streaming/channels/1/picture%3FsnapShotImageType=JPEG"
            ""
            "/Streaming/channels/1/picture"
            "/Streaming/channels/1/picture"
            "snapShotImageType=JPEG"
            

            Which is exactly what I'd expect (given that the default argument to QUrl::path is QUrl::FullyDecoded).

            Edit:

            Just adding an example that's a little closer to your original post:

                QUrl url("http://admin@192.168.1.64");
                url.setPath("/Streaming/channels/1/picture?snapShotImageType=JPEG");
                qDebug() << url.toString(QUrl::FullyEncoded);
            

            Output:

            "http://admin@192.168.1.64/Streaming/channels/1/picture%3FsnapShotImageType=JPEG"
            

            Cheers.

            AlexorleonA Offline
            AlexorleonA Offline
            Alexorleon
            wrote on last edited by
            #5

            @Paul-Colby
            "http://admin@192.168.1.64/Streaming/channels/1/picture%3FsnapShotImageType=JPEG" this is address of the IP-camera. It does not work with %3F.
            And if I use setPath, it changes the value automatically.

            I do this so:

            QString strUrl("http://admin@192.168.1.64/Streaming/channels/1/picture?snapShotImageType=JPEG");
            QUrl url(strUrl);
            

            Output:

            QUrl("http://admin@192.168.1.64/Streaming/channels/1/picture?snapShotImageType=JPEG")
            

            It is right for me.

            Paul ColbyP 1 Reply Last reply
            0
            • AlexorleonA Alexorleon

              @Paul-Colby
              "http://admin@192.168.1.64/Streaming/channels/1/picture%3FsnapShotImageType=JPEG" this is address of the IP-camera. It does not work with %3F.
              And if I use setPath, it changes the value automatically.

              I do this so:

              QString strUrl("http://admin@192.168.1.64/Streaming/channels/1/picture?snapShotImageType=JPEG");
              QUrl url(strUrl);
              

              Output:

              QUrl("http://admin@192.168.1.64/Streaming/channels/1/picture?snapShotImageType=JPEG")
              

              It is right for me.

              Paul ColbyP Offline
              Paul ColbyP Offline
              Paul Colby
              wrote on last edited by Paul Colby
              #6

              @Alexorleon said in QUrl setPath with the symbol '?':

              http://admin@192.168.1.64/Streaming/channels/1/picture%3FsnapShotImageType=JPEG" this is address of the IP-camera. It does not work with %3F.

              Who, or what, tells you that's the "address of the IP-camera"?

              Typically web-based APIs would use a ? there, not %3F, since most API servers would be sending all requests to the same */picture endpoint, then passing the image type as an optional query parameter to that endpoint. This is convention only, the standards don't require it. But it does suggest that whoever / whatever told you that the URL contains a %3F was mistaken. Perhaps some poorly-translated-to-English manual?

              Indeed, it appears (just based on the URL format) that you are using a Hikvision device, and those, the snapShotImageType is a query parameter, so should be preceded by a ? or &, according to their user manuals (such as this one). So I think you have your input URL wrong to begin with.

              Cheers.

              AlexorleonA 1 Reply Last reply
              2
              • Paul ColbyP Paul Colby

                @Alexorleon said in QUrl setPath with the symbol '?':

                http://admin@192.168.1.64/Streaming/channels/1/picture%3FsnapShotImageType=JPEG" this is address of the IP-camera. It does not work with %3F.

                Who, or what, tells you that's the "address of the IP-camera"?

                Typically web-based APIs would use a ? there, not %3F, since most API servers would be sending all requests to the same */picture endpoint, then passing the image type as an optional query parameter to that endpoint. This is convention only, the standards don't require it. But it does suggest that whoever / whatever told you that the URL contains a %3F was mistaken. Perhaps some poorly-translated-to-English manual?

                Indeed, it appears (just based on the URL format) that you are using a Hikvision device, and those, the snapShotImageType is a query parameter, so should be preceded by a ? or &, according to their user manuals (such as this one). So I think you have your input URL wrong to begin with.

                Cheers.

                AlexorleonA Offline
                AlexorleonA Offline
                Alexorleon
                wrote on last edited by
                #7

                @Paul-Colby

                This address was in the manual.
                Yes you are right. If I delete the "?snapShotImageType=JPEG" is still running.

                Thanks to all.

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  Jerome Godbout
                  wrote on last edited by
                  #8

                  The problem is the path and the query argument are not the same thing. Everything that goes before the '?' is the path and after it should be set into the setQuery():

                  const QStringList path_part = path.split('?');
                  url.setPath(path_part.at(0));
                  if(path_part.size() > 1)
                  url.setQuery(path_part.at(1));

                  This will work properly. A path with ? would indeed get encoded with %3F

                  1 Reply Last reply
                  2

                  • Login

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