QUrl and special characters(#)

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

    netManager = new QNetworkAccessManager(this);

    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?

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

  • 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.

  • Moderators

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

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

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.