Logo Search packages:      
Sourcecode: qt4-x11 version File versions  Download package

QUrl Class Reference

List of all members.


Detailed Description

The QUrl class provides a convenient interface for working with URLs.

It can parse and construct URLs in both encoded and unencoded form. QUrl also has support for internationalized domain names (IDNs).

The most common way to use QUrl is to initialize it via the constructor by passing a QString. Otherwise, setUrl() and setEncodedUrl() can also be used.

URLs can be represented in two forms: encoded or unencoded. The unencoded representation is suitable for showing to users, but the encoded representation is typically what you would send to a web server.

        // Unencoded URL
        "http://b├╝hler.example.com/List of applicants.xml"

        // Encoded URL
        "http://xn--bhler-kva.example.com/List%20of%20applicants.xml"

A URL can also be constructed piece by piece by calling setScheme(), setUserName(), setPassword(), setHost(), setPort(), setPath(), setEncodedQuery() and setFragment(). Some convenience functions are also available: setAuthority() sets the user name, password, host and port. setUserInfo() sets the user name and password at once.

Call isValid() to check if the URL is valid. This can be done at any point during the constructing of a URL.

Constructing a query is particularily convenient through the use of setQueryItems(), addQueryItem() and removeQueryItem(). Use setQueryDelimiters() to customize the delimiters used for generating the query string.

For the convenience of generating encoded URL strings or query strings, there are two static functions called fromPercentEncoding() and toPercentEncoding() which deal with percent encoding and decoding of QStrings.

Calling isRelative() will tell whether or not the URL is relative. A relative URL can be resolved by passing it as argument to resolved(), which returns an absolute URL. isParentOf() is used for determining whether one URL is a parent of another.

fromLocalFile() constructs a QUrl by parsing a local file path. toLocalFile() converts a URL to a local file path.

The human readable representation of the URL is fetched with toString(). This representation is appropriate for displaying a URL to a user in unencoded form. The encoded form however, as returned by toEncoded(), is for internal use, passing to web servers, mail clients and so on.

QUrl conforms to the URI specification from {http://www.ietf.org/rfc/rfc3986.txt}{RFC3986} (Uniform Resource Identifier: Generic Syntax), and includes scheme extensions from {http://www.ietf.org/rfc/rfc1738.txt}{RFC1738} (Uniform Resource Locators).

Definition at line 37 of file qurl.h.


Public Types

enum  FormattingOption {
  None = 0x0, RemoveScheme = 0x1, RemovePassword = 0x2, RemoveUserInfo = RemovePassword | 0x4,
  RemovePort = 0x8, RemoveAuthority = RemoveUserInfo | RemovePort | 0x10, RemovePath = 0x20, RemoveQuery = 0x40,
  RemoveFragment = 0x80, StripTrailingSlash = 0x10000
}
enum  ParsingMode { TolerantMode, StrictMode }

Public Member Functions

void addQueryItem (const QString &key, const QString &value)
QStringList allQueryItemValues (const QString &key) const
QString authority () const
void clear ()
void detach ()
QByteArray encodedQuery () const
QString fragment () const
bool hasQueryItem (const QString &key) const
QString host () const
bool isDetached () const
bool isEmpty () const
bool isParentOf (const QUrl &url) const
bool isRelative () const
bool isValid () const
bool operator!= (const QUrl &url) const
bool operator< (const QUrl &url) const
QUrloperator= (const QString &url)
QUrloperator= (const QUrl &copy)
bool operator== (const QUrl &url) const
QString password () const
QString path () const
int port (int defaultPort) const
int port () const
QList< QPair< QString, QString > > queryItems () const
QString queryItemValue (const QString &key) const
char queryPairDelimiter () const
char queryValueDelimiter () const
 QUrl (const QUrl &copy)
 QUrl (const QString &url, ParsingMode mode)
 QUrl (const QString &url)
 QUrl ()
void removeAllQueryItems (const QString &key)
void removeQueryItem (const QString &key)
QUrl resolved (const QUrl &relative) const
QString scheme () const
void setAuthority (const QString &authority)
void setEncodedQuery (const QByteArray &query)
void setEncodedUrl (const QByteArray &url, ParsingMode mode)
void setEncodedUrl (const QByteArray &url)
void setFragment (const QString &fragment)
void setHost (const QString &host)
void setPassword (const QString &password)
void setPath (const QString &path)
void setPort (int port)
void setQueryDelimiters (char valueDelimiter, char pairDelimiter)
void setQueryItems (const QList< QPair< QString, QString > > &query)
void setScheme (const QString &scheme)
void setUrl (const QString &url, ParsingMode mode)
void setUrl (const QString &url)
void setUserInfo (const QString &userInfo)
void setUserName (const QString &userName)
QByteArray toEncoded (FormattingOptions options=None) const
QString toLocalFile () const
QString toString (FormattingOptions options=None) const
QString userInfo () const
QString userName () const
 ~QUrl ()

Static Public Member Functions

static QUrl fromEncoded (const QByteArray &url, ParsingMode mode)
static QUrl fromEncoded (const QByteArray &url)
static QUrl fromLocalFile (const QString &localfile)
static QString fromPercentEncoding (const QByteArray &)
static QString fromPunycode (const QByteArray &)
static QByteArray toPercentEncoding (const QString &, const QByteArray &exclude=QByteArray(), const QByteArray &include=QByteArray())
static QByteArray toPunycode (const QString &)

Private Attributes

QUrlPrivate * d

Related Functions

(Note that these are not member functions.)

QDataStreamoperator<< (QDataStream &out, const QUrl &url)
QDataStreamoperator>> (QDataStream &in, QUrl &url)

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index