The individual parts of a URL can be set with setProtocol(), setHost(), setPort(), setPath(), setFileName(), setRef() and setQuery(). A URL could contain, for example, an ftp address which requires a user name and password; these can be set with setUser() and setPassword().
Because path is always encoded internally you must not use "%00" in the path, although this is okay (but not recommended) for the query.
.PP
QUrl is normally used like this:
.PP
.nf
.br
QUrl url( "http://www.trolltech.com" );
.br
// or
.br
QUrl url( "file:/home/myself/Mail", "Inbox" );
.br
.fi
.PP
You can then access and manipulate the various parts of the URL.
.PP
To make it easy to work with QUrls and QStrings, QUrl implements the necessary cast and assignment operators so you can do following:
.PP
.nf
.br
QUrl url( "http://www.trolltech.com" );
.br
QString s = url;
.br
// or
.br
QString s( "http://www.trolltech.com" );
.br
QUrl url( s );
.br
.fi
.PP
Use the static functions, encode() and decode() to encode or decode a URL in a string. (They operate on the string in-place.) The isRelativeUrl() static function returns TRUE if the given string is a relative URL.
.PP
If you want to use a URL to work on a hierarchical structure (e.g. a local or remote filesystem), you might want to use the subclass QUrlOperator.
.PP
See also QUrlOperator, Input/Output and Networking, and Miscellaneous Classes.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QUrl::QUrl ()"
Constructs an empty URL that is invalid.
.SH "QUrl::QUrl ( const QString & url )"
Constructs a URL by parsing the string \fIurl\fR.
.PP
If you pass a string like "/home/qt", the "file" protocol is assumed.
Constructs an URL taking \fIurl\fR as the base (context) and \fIrelUrl\fR as a relative URL to \fIurl\fR. If \fIrelUrl\fR is not relative, \fIrelUrl\fR is taken as the new URL.
will result in a new URL, with "/usr/local" as the path and "file" as the protocol.
.PP
Normally it is expected that the path of \fIurl\fR points to a directory, even if the path has no slash at the end. But if you want the constructor to handle the last part of the path as a file name if there is no slash at the end, and to let it be replaced by the file name of \fIrelUrl\fR (if it contains one), set \fIcheckSlash\fR to TRUE.
.SH "QUrl::~QUrl ()\fC [virtual]\fR"
Destructor.
.SH "void QUrl::addPath ( const QString & pa )\fC [virtual]\fR"
Decodes the \fIurl\fR in-place into UTF-8. For example
.PP
.nf
.br
QString url = "http%3A//www%20trolltech%20com"
.br
QUrl::decode( url );
.br
// url is now "http://www.trolltech.com"
.br
.fi
.PP
See also encode().
.SH "QString QUrl::dirPath () const"
Returns the directory path of the URL. This is the part of the path of the URL without the fileName(). See the documentation of fileName() for a discussion of what is handled as file name and what is handled as directory path.
Returns the file name of the URL. If the path of the URL doesn't have a slash at the end, the part between the last slash and the end of the path string is considered to be the file name. If the path has a slash at the end, an empty string is returned here.
.PP
See also setFileName().
.PP
Example: network/networkprotocol/nntp.cpp.
.SH "bool QUrl::hasHost () const"
Returns TRUE if the URL contains a hostname; otherwise returns FALSE.
.PP
See also setHost().
.SH "bool QUrl::hasPassword () const"
Returns TRUE if the URL contains a password; otherwise returns FALSE.
.PP
\fBWarning:\fR Passwords passed in URLs are normally \fIinsecure\fR; this is due to the mechanism, not because of Qt.
.PP
See also setPassword() and setUser().
.SH "bool QUrl::hasPath () const"
Returns TRUE if the URL contains a path; otherwise returns FALSE.
.PP
See also path() and setPath().
.SH "bool QUrl::hasPort () const"
Returns TRUE if the URL contains a port; otherwise returns FALSE.
.PP
See also setPort().
.SH "bool QUrl::hasRef () const"
Returns TRUE if the URL has a reference; otherwise returns FALSE.
.PP
See also setRef().
.SH "bool QUrl::hasUser () const"
Returns TRUE if the URL contains a username; otherwise returns FALSE.
Returns the path of the URL. If \fIcorrect\fR is TRUE, the path is cleaned (deals with too many or too few slashes, cleans things like "/../..", etc). Otherwise path() returns exactly the path that was parsed or set.
.PP
See also setPath() and hasPath().
.PP
Example: qdir/qdir.cpp.
.SH "int QUrl::port () const"
Returns the port of the URL or -1 if no port has been set.
.PP
See also setPort().
.SH "QString QUrl::protocol () const"
Returns the protocol of the URL. Typically, "file", "http", "ftp", etc.
Composes a string version of the URL and returns it. If \fIencodedPath\fR is TRUE the path in the returned string is encoded. If \fIforcePrependProtocol\fR is TRUE and \fIencodedPath\fR looks like a local filename, the "file:/" protocol is also prepended.
.PP
See also encode() and decode().
.SH "QString QUrl::user () const"
Returns the username of the URL.
.PP
See also setUser() and setPassword().
.SH "SEE ALSO"
.BR http://doc.trolltech.com/qurl.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive Qt documentation is provided in HTML format; it is
located at $QTDIR/doc/html and can be read using Qt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech.
.P
If you find errors in this manual page, please report them to
.BR qt-bugs@trolltech.com .
Please include the name of the manual page (qurl.3qt) and the Qt