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 format QString to remove % and & symbols for URL requests

How to format QString to remove % and & symbols for URL requests

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 3.5k 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 Offline
    A Offline
    aashish.lg
    wrote on last edited by
    #1

    I am using QWebView to display some html content, I have created one html file which launches some adobe flash content.
    inside the html code for flash there is a src attribute which is nothing but a URL for the flash video,
    which is having some % and & signs.
    Adobe flash player plugin 10.3 and above does not take any % and & sign in the URL string.
    So any idea how can I format my QString, which has HTML code , so that it will remove % and & signs and will replace these with some appropriate char set. Below mention is my html code that I stored in QString.

    @<html><body topmargin="0" leftmargin="0"><embed type="application/x-shockwave-flash" src="http://c.brightcove.com/services/viewer/federated_f9?&width=640&height=360&flashID=si_brightcove_experience&bgcolor=#000000&playerID=836271999001&playerKey=AQ~~,AAAAAGLxMrc~,SBQ2diQT3MIL51Crxxrcp2NU67P7DVl1&isVid=true&isUI=true&wmode=transparent&dynamicStreaming=true&@videoPlayer=1719922980001&autoStart=&debuggerID=&startTime=1342613597675" width="100%" height="100%" seamlesstabbing="false" class="BrightcoveExperience" id="si_brightcove_experience" data="http://c.brightcove.com/services/viewer/federated_f9?&width=640&height=360&flashID=si_brightcove_experience&bgcolor=#000000&playerID=836271999001&playerKey=AQ~~,AAAAAGLxMrc~,SBQ2diQT3MIL51Crxxrcp2NU67P7DVl1&isVid=true&isUI=true&wmode=transparent&dynamicStreaming=true&@videoPlayer=1719922980001&autoStart=&debuggerID=&startTime=1342613597675" type="application/x-shockwave-flash" PARAM="" allowScriptAccess="always" allowFullScreen="true" seamlessTabbing="false" swliveconnect="0" wmode="transparent" quality="high" bgcolor="#000000"></body></html>@

    1 Reply Last reply
    0
    • A Offline
      A Offline
      absfrm
      wrote on last edited by
      #2

      C++ Native
      @
      std::string s = SOME_STR;
      std::replace( s.begin(), s.end(), '%', ''); // replace all '%' within 'empty symbol'
      std::replace( s.begin(), s.end(), '&', ''); // replace all '&' within 'empty symbol'
      @

      in qt :
      @
      QString s = "%%%text text text text text text text text&&&&text texttext text&&&&";
      s.replace("%",""); // replace all '%' within 'empty symbol'
      s.replace("&",""); // replace all '&' within 'empty symbol'
      @

      If You Want You Can!

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Another example:

        ..the method:
        @void MyClass::replaceCharacter(QString &string, const char illegalCharacters[], const int &illegalCharactersSize, const char &characterToReplace) {

        for(int index(0); index < illegalCharactersSize; ++index) {
        
            string.replace(illegalCharacters[index], characterToReplace);
        
        }// for
        

        }// replaceCharacter@

        ...the call:
        @QString url = "This%is&a@test.";

        char illegalCharacters[4] = { '%', '&', '=', '@' };

        int illegalCharactersSize = sizeof(illegalCharacters);

        MyClass myclass;

        myclass.replaceCharacter(url, illegalCharacters, illegalCharactersSize, '_');@

        1 Reply Last reply
        0
        • A Offline
          A Offline
          aashish.lg
          wrote on last edited by
          #4

          No Guyz you people misunderstood my requirements.
          I am looking to format my QString in to a format which will be aligned to url char format.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mlong
            wrote on last edited by
            #5

            So, you're basically needing to parse, unencode, and simplify a URL?

            If so, look at the QUrl documentation. It has some methods which may be helpful for you. "fromPercentEncoding":/doc/qt-4.8/qurl.html#fromPercentEncoding might be a good start. "path":/doc/qt-4.8/qurl.html#pathx and the queryItem methods might also be helpful as well.

            (You'd have to manually pull out the URLs from the XML, of course, to process them.)

            Software Engineer
            My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

            1 Reply Last reply
            0

            • Login

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