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 and special characters(#)
QtWS25 Last Chance

QUrl and special characters(#)

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 4.1k 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.
  • L Offline
    L Offline
    leonidwang
    wrote on last edited by
    #1

    My Qt-based client is sending a HTTP request to a server with Qurl, for example

    @
    netManager = new QNetworkAccessManager(this);
    netManager->get(QNetworkRequest(QUrl("http://www.somesite.com/query.php?file=filename")));
    @

    The problem is the filename I passed as a PHP parameter can contain some special characters like "#".
    "/path/to/some#file" is a valid file path, but if I pass this string in QUrl, the #file will get truncated because
    "#" is recognized as fragment indicator(or "named anchor"), so the server side PHP program will receive a query
    with file name set to "/path/to/some", that's not my intention.

    Do I have to work around this problem by myself? or is there any existing solution with QUrl?

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

      Do not use the [[Doc:QUrl]] constructor like this (or, probably, at all). Use one of the static functions to construct your URL instead.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        leonidwang
        wrote on last edited by
        #3

        OK, I figured out that I should not use QUrl::QUrl ( const QString & url ).
        QUrl's member functions setScheme() setAuthority() setPath() setQueryItems() solved my problem.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          as a side not, AFAIK this will be fixed in Qt5.

          (Z(:^

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            That's right: QUrl will be overhauled in Qt5.

            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