class KUrl


Table of contents
Modules
kdecore Classes
All Classes
Module kdecore
Namespace global
Class KUrl
Inherits QUrl

Represents and parses a URL.

A prototypical URL looks like:

#reference

KUrl handles escaping of URLs. This means that the specification of a full URL will differ from the corresponding string that would specify a local file or directory in file-operations like fopen. This is because an URL #'->"%23", space->"%20") #' is used to specify a "reference", i.e. the position within a document).

The constructor KUrl(const QString&) expects a string properly escaped, or at least non-ambiguous. If you have the absolute path you should use KUrl.fromPath(const QString&).

##");
QString url = kurl.url(); // . "file:///bar/%23foo%23"

If you have the URL of a local file or directory and need the absolute path, you would use path().

KUrl url( "file:///bar/%23foo%23" );
...
if ( url.isLocalFile() )
##"

This must also be considered when you have separated directory and file strings and need to put them together. While you can simply concatenate normal path strings, you must take care if the directory-part is already an escaped URL. (This might be needed if the user specifies a relative path, and your program supplies the rest from elsewhere.)

Wrong:

QString dirUrl = "file:///bar/";
##";
##" won't behave like you would expect.
Instead you should use addPath(): Right:
KUrl url( "file:///bar/" );
##";
url.addPath( fileName );
QString validURL = url.url(); // . "file:///bar/%23foo%23"

Also consider that some URLs contain the password, but this shouldn't be visible. Your program should use prettyUrl() every time it displays a URL, whether in the GUI or in debug output or...

KUrl url( "ftp://name:password@ftp.faraway.org/bar/%23foo%23");
QString visibleURL = url.prettyUrl(); // . "ftp://name@ftp.faraway.org/bar/%23foo%23"
Note that prettyUrl() doesn't change the character escapes (like "%23"). Otherwise the URL would be invalid and the user wouldn't be able to use it in another context.



enums

enum details

methods