Results 1 to 4 of 4

Thread: QUrl with percent signs Issue

  1. #1
    Join Date
    Jan 2014
    Posts
    3
    Qt products
    Qt4

    Question QUrl with percent signs Issue

    Hello everyone

    Just started QML a few days ago and I am a bit confused.

    I am trying to send a HTTP request to a webserver through QNetworkRequest.

    My QUrl should have this: http://127.0.0.1/subdomain/PW?t=Someword&p=%01
    But it seems that it changes it all the time to this: http://127.0.0.1/subdomain/PW?t=Someword&p=%2501

    How would I get QUrl to not change the percent sign and keep it as it is?

    I tried the below without success

    QUrl url = QUrl::fromEncoded("http%3A//127.0.0.1/subdomain/PW%3Ft%3DSomeword%26p%3D%2501");

    Any help would be appreciated
    thanks
    Last edited by K_rol; 22nd January 2014 at 03:24.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QUrl with percent signs Issue

    Works fine here with Qt 5.2:
    Qt Code:
    1. QUrl url1("http://127.0.0.1/subdomain/PW?t=Someword&p=%01");
    2. QUrl url2 = QUrl::fromEncoded("http://127.0.0.1/subdomain/PW?t=Someword&p=%01");
    3. qDebug() << url1.toString(QUrl::FullyEncoded);
    4. qDebug() << url2.toString(QUrl::FullyEncoded);
    5.  
    6. /* Output
    7. "http://127.0.0.1/subdomain/PW?t=Someword&p=%01"
    8. "http://127.0.0.1/subdomain/PW?t=Someword&p=%01"
    9. */
    To copy to clipboard, switch view to plain text mode 

    If the "01" following "%" is not the digits 0 and 1, for example the letters o and l, then the percent sign will be corrected because it must be followed by two hex digits. See the QUrl doc about ParseMode::Tolerant.

  3. #3
    Join Date
    Jan 2014
    Posts
    3
    Qt products
    Qt4

    Default Re: QUrl with percent signs Issue

    Thanks for you reply

    Not sure of what I could be doing wrong... it always only shows "http://127.0.0.1/subdomain/PW?t=Someword&p=%2501"

    Qt Code:
    1. QUrl url1("http://127.0.0.1/subdomain/PW?t=Someword&p=%01");
    2. QString urlString1; urlString1 = url1.toEncoded();
    3. std::cout << qPrintable(urlString1);
    To copy to clipboard, switch view to plain text mode 

    I noticed QUrl::FullyEncoded is only in QT5.

    Could QT4 has a different take on the percent sign ? Seems unlikely to me :\
    Last edited by K_rol; 22nd January 2014 at 18:23. Reason: added code

  4. #4
    Join Date
    Jan 2014
    Posts
    3
    Qt products
    Qt4

    Default Re: QUrl with percent signs Issue

    Got it to work!
    Just for future references to anyone else, someone pointed out to me the below codes:
    Qt Code:
    1. QByteArray rawQuery("t=Someword&p=%01");
    2. QUrl command("http://127.0.0.1/subdomain/letters");
    3. command.setEncodedQuery(rawQuery);
    4. std::cout << command.toEncoded().data();
    To copy to clipboard, switch view to plain text mode 
    Result "http://127.0.0.1/subdomain/letters?t=Someword&p=%01"


    Explanation from http://doc.qt.io/qt-4.8/qurl.html#setEncodedQuery


    Sets the query string of the URL to query. The string is inserted as-is, and no further encoding is performed when calling toEncoded().
    This function is useful if you need to pass a query string that does not fit into the key-value pattern, or that uses a different scheme for encoding special characters than what is suggested by QUrl.
    Passing a value of QByteArray() to query (a null QByteArray) unsets the query completely. However, passing a value of QByteArray("") will set the query to an empty value, as if the original URL had a lone "?".

Similar Threads

  1. Replies: 1
    Last Post: 18th April 2012, 10:40
  2. QTranslator and polish signs
    By damon_1990 in forum Newbie
    Replies: 0
    Last Post: 11th December 2011, 22:04
  3. QUrl and https
    By TomASS in forum Newbie
    Replies: 1
    Last Post: 15th March 2010, 22:49
  4. QUrl and EUC-JP
    By Ignacio Serantes in forum Qt Programming
    Replies: 1
    Last Post: 22nd February 2009, 15:19
  5. QUrl parsing?
    By gfunk in forum Qt Programming
    Replies: 2
    Last Post: 17th January 2008, 10:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.