QUrl Class Reference
The QUrl class provides a URL parser and simplifies working with URLs.
More...
#include <qurl.h>
Inherited by QUrlOperator.
List of all member functions.
Public Members
QUrl ( const QString & url )
QUrl ( const QUrl & url )
QUrl ( const QUrl & url, const QString & relUrl, bool checkSlash = FALSE )
virtual void
setUser ( const QString & user )
virtual void
setHost ( const QString & host )
QString
path ( bool correct = TRUE ) const
virtual void
setPath ( const QString & path )
virtual void
setQuery ( const QString & txt )
virtual void
setRef ( const QString & txt )
virtual void
addPath ( const QString & pa )
virtual QString
toString ( bool encodedPath = FALSE, bool forcePrependProtocol = TRUE ) const
Static Public Members
Protected Members
virtual bool
parse ( const QString & url )
Detailed Description
The QUrl class provides a URL parser and simplifies working with URLs.
The QUrl class is provided for simple work with URLs.
It does all parsing, decoding, encoding, and so on.
Mention that URL has some restrictions regarding the path
encoding. URL works with the decoded path and
encoded query in turn. For example in the following
http://localhost/cgi-bin/test%20me.pl?cmd=Hello%20you
would result in a decoded path "/cgi-bin/test me.pl"
and in the encoded query "cmd=Hello%20you".
Because path is always encoded internally you may NOT use
"%00" in the path, although this is ok for the query.
QUrl is normally used like that:
QUrl u( "http://www.trolltech.com" );
// or
QUrl u( "file:/home/myself/Mail", "Inbox" );
You can then access the parts of the URL, change and use them.
To allow easy work with QUrl and QString together, QUrl implements
the needed cast and assign operators so you can do following:
QUrl u( "http://www.trolltech.com" );
QString s = u;
// or
QString s( "http://www.trolltech.com" );
QUrl u( s );
If you want to use an URL to work on a hirarchical structure
(e.g., a local or remote filesystem), the class QUrlOperator which is derived
from QUrl may be of interest to you.
See also QUrlOperator, Input/Output and Networking and Miscellaneous Classes.
Member Function Documentation
QUrl::QUrl ()
Constructs an empty URL that is invalid.
QUrl::QUrl ( const QString & url )
Constructs an URL using url and parses this string.
You can pass strings such as "/home/qt"; in this case the protocol
"file" is assumed.
QUrl::QUrl ( const QUrl & url )
Copy constructor. Copies the data of url.
QUrl::QUrl ( const QUrl & url, const QString & relUrl, bool checkSlash = FALSE )
Constructs an URL taking url as base (context) and
relUrl as relative URL to url. If relUrl is not relative,
relUrl is taken as the new URL.
For example, the path of
QUrl u( "ftp://ftp.trolltech.com/qt/source", "qt-2.1.0.tar.gz" );
will be "/qt/srource/qt-2.1.0.tar.gz".
And
QUrl u( "ftp://ftp.trolltech.com/qt/source", "/usr/local" );
will result in a new URL: "ftp://ftp.trolltech.com/usr/local",
And
QUrl u( "ftp://ftp.trolltech.com/qt/source", "file:/usr/local" );
will result in a new URL, with "/usr/local" as path
and "file" as protocol.
Normally it is expected that the path of url 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 file name if there is no slash at the end,
and to let it be replaced by the file name of relUrl
(if it contains one), set checkSlash to TRUE.
QUrl::~QUrl () [virtual]
Destructor.
void QUrl::addPath ( const QString & pa ) [virtual]
Adds the path pa to the path of the URL.
bool QUrl::cdUp () [virtual]
Goes one directory up.
void QUrl::decode ( QString & url ) [static]
Decodes the string url.
QString QUrl::dirPath () const
Returns the directory path of the URL. This is the part
of the path of this 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.
Example: network/networkprotocol/nntp.cpp.
void QUrl::encode ( QString & url ) [static]
Encodes the string url.
QString QUrl::encodedPathAndQuery ()
Returns the encoded path plus the query (also encoded).
QString QUrl::fileName () const
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 handled as file name. If the
path has a slash at the end, an empty string is returned here.
Example: network/networkprotocol/nntp.cpp.
bool QUrl::hasHost () const
Returns TRUE if the URL contains a hostname,
otherwise FALSE.
bool QUrl::hasPassword () const
Returns TRUE if the URL contains a password,
otherise FALSE.
bool QUrl::hasPath () const
Returns TRUE if the URL contains a path,
otherwise FALSE.
bool QUrl::hasRef () const
Returns TRUE if the URL has a reference, otherwise FALSE.
bool QUrl::hasUser () const
Returns TRUE if the URL contains a username,
otherwise FALSE.
QString QUrl::host () const
Returns the hostname of the URL.
bool QUrl::isLocalFile () const
Returns TRUE if the URL is a local file, otherwise FALSE.
Example: qdir/qdir.cpp.
bool QUrl::isRelativeUrl ( const QString & url ) [static]
Returns TRUE if url is relative, otherwise FALSE.
bool QUrl::isValid () const
Returns TRUE if the URL is valid, otherwise FALSE.
An URL is invalid in case of a parse error, for example.
QUrl::operator QString () const
Composes a string of the URL and returns it.
See also QUrl::toString().
QUrl & QUrl::operator= ( const QUrl & url )
Assigns the data of url to this class.
QUrl & QUrl::operator= ( const QString & url )
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Parses url and assigns the resulting data to this class.
You can pass strings such as "/home/qt"; in this case the protocol
"file" is assumed.
bool QUrl::operator== ( const QUrl & url ) const
Compares this URL with url and returns TRUE if they are equal,
otherwise FALSE.
bool QUrl::operator== ( const QString & url ) const
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Compares this URL with url. url is parsed
first. Returns TRUE if url is equal to this url,
otherwise FALSE:
bool QUrl::parse ( const QString & url ) [virtual protected]
Parses the url.
QString QUrl::password () const
Returns the password of the URL.
QString QUrl::path ( bool correct = TRUE ) const
Returns the path of the URL. If correct 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.
Example: qdir/qdir.cpp.
int QUrl::port () const
Returns the port of the URL.
QString QUrl::protocol () const
Returns the protocol of the URL. It is something like
"file" or "ftp".
QString QUrl::query () const
Returns the query (encoded) of the URL.
QString QUrl::ref () const
Returns the reference (encoded) of the URL.
void QUrl::reset () [virtual protected]
Resets all parts of the URL to their default values
and invalidates it.
void QUrl::setEncodedPathAndQuery ( const QString & pathAndQuery ) [virtual]
Parses pathAndQuery for a path and query and sets those values. The whole
string has to be encoded.
See also encode().
void QUrl::setFileName ( const QString & name ) [virtual]
Sets the file name of the URL to name. If this
url contains a fileName(), this is replaced by
name. See the documentation of fileName()
for a more detailed discussion of what is handled
as file name and what is handled as directory path.
void QUrl::setHost ( const QString & host ) [virtual]
Sets the hostname of the URL to host.
void QUrl::setPassword ( const QString & pass ) [virtual]
Sets the password of the URL to pass.
void QUrl::setPath ( const QString & path ) [virtual]
Sets the path of the URL to path.
void QUrl::setPort ( int port ) [virtual]
Sets the port of the URL to port.
void QUrl::setProtocol ( const QString & protocol ) [virtual]
Sets the protocol of the URL to protocol. This could be
"file", "ftp" or similar.
void QUrl::setQuery ( const QString & txt ) [virtual]
Sets the query of the URL to txt. txt must be encoded.
void QUrl::setRef ( const QString & txt ) [virtual]
Sets the reference of the URL to txt. txt must be encoded.
void QUrl::setUser ( const QString & user ) [virtual]
Sets the username of the URL to user.
QString QUrl::toString ( bool encodedPath = FALSE, bool forcePrependProtocol = TRUE ) const [virtual]
Composes a string of the URL and returns it. If encodedPath is
TRUE the path in the returned string is encoded. If forcePrependProtocol is TRUE and encodedPath looks like a local
filename, the "file:/" protocol is also prepended.
QString QUrl::user () const
Returns the username of the URL.
Search the documentation, FAQ, qt-interest archive and more (uses
www.trolltech.com):
This file is part of the Qt toolkit,
copyright © 1995-2001
Trolltech, all rights reserved.
Copyright © 2001 Trolltech | Trademarks
| Qt version 3.0.0-beta3
|