2

I have a QUrl and I need to extract the path+file+params. Basically everything but the hostname - what would be requested via HTTP.

I looked through the Qt 4.6 docs but I couldn't find anything that looked like it would do this.

What method(s) would I call?

Nathan Osman
  • 71,149
  • 71
  • 256
  • 361

1 Answers1

8

You can clear the scheme with setScheme. After that the url will be relative so it shouldn't return the hostname anymore when converting it to a string.

QUrl someUrl("http://stackoverflow.com/foo/bar?spam=eggs");
someUrl.setScheme("");
someUrl.toString();

Or, you can give the toString() method some extra parameters:

QUrl someUrl("http://stackoverflow.com/foo/bar?spam=eggs");
someUrl.toString(QUrl::RemoveScheme);
Wolph
  • 78,177
  • 11
  • 137
  • 148
  • Thanks. That'll work just great. One more question - when I call toString, does it return a URL-encoded string? – Nathan Osman Aug 19 '10 at 04:21
  • 1
    For an urlencoded `toString` you can use `toEncoded`. Docs: http://doc.trolltech.com/4.6/qurl.html#toEncoded – Wolph Aug 19 '10 at 11:49