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

Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | Related Functions

QUrl Class Reference

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

Collaboration diagram for QUrl:
Collaboration graph

List of all members.

Public Types

typedef QUrlPrivateDataPtr
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 addEncodedQueryItem (const QByteArray &key, const QByteArray &value)
void addQueryItem (const QString &key, const QString &value)
QList< QByteArrayallEncodedQueryItemValues (const QByteArray &key) const
QStringList allQueryItemValues (const QString &key) const
QString authority () const
void clear ()
DataPtrdata_ptr ()
void detach ()
QByteArray encodedFragment () const
QByteArray encodedHost () const
QByteArray encodedPassword () const
QByteArray encodedPath () const
QByteArray encodedQuery () const
QList< QPair< QByteArray,
QByteArray > > 
encodedQueryItems () const
QByteArray encodedQueryItemValue (const QByteArray &key) const
QByteArray encodedUserName () const
QString errorString () const
QString fragment () const
bool hasEncodedQueryItem (const QByteArray &key) const
bool hasFragment () const
bool hasQuery () 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 QUrl &copy)
QUrloperator= (const QString &url)
bool operator== (const QUrl &url) const
QString password () const
QString path () const
int port () const
int port (int defaultPort) const
QList< QPair< QString, QString > > queryItems () const
QString queryItemValue (const QString &key) const
char queryPairDelimiter () const
char queryValueDelimiter () const
 QUrl ()
 QUrl (const QUrl &copy)
 QUrl (const QString &url)
 QUrl (const QString &url, ParsingMode mode)
void removeAllEncodedQueryItems (const QByteArray &key)
void removeAllQueryItems (const QString &key)
void removeEncodedQueryItem (const QByteArray &key)
void removeQueryItem (const QString &key)
QUrl resolved (const QUrl &relative) const
QString scheme () const
void setAuthority (const QString &authority)
void setEncodedFragment (const QByteArray &fragment)
void setEncodedHost (const QByteArray &host)
void setEncodedPassword (const QByteArray &password)
void setEncodedPath (const QByteArray &path)
void setEncodedQuery (const QByteArray &query)
void setEncodedQueryItems (const QList< QPair< QByteArray, QByteArray > > &query)
void setEncodedUrl (const QByteArray &url)
void setEncodedUrl (const QByteArray &url, ParsingMode mode)
void setEncodedUserName (const QByteArray &userName)
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)
void setUrl (const QString &url, ParsingMode mode)
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 QString fromAce (const QByteArray &)
static QUrl fromEncoded (const QByteArray &url)
static QUrl fromEncoded (const QByteArray &url, ParsingMode mode)
static QUrl fromLocalFile (const QString &localfile)
static QString fromPercentEncoding (const QByteArray &)
static QString fromPunycode (const QByteArray &)
static QStringList idnWhitelist ()
static void setIdnWhitelist (const QStringList &)
static QByteArray toAce (const QString &)
static QByteArray toPercentEncoding (const QString &, const QByteArray &exclude=QByteArray(), const QByteArray &include=QByteArray())
static QByteArray toPunycode (const QString &)

Private Attributes


Related Functions

(Note that these are not member functions.)

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

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. For example, the unencoded URL "http://b\uuml\c{}hler.example.com" would be sent to the server as "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 particularly 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 {RFC 3986} (Uniform Resource Identifier: Generic Syntax), and includes scheme extensions from {RFC 1738} (Uniform Resource Locators). Case folding rules in QUrl conform to {RFC 3491} (Nameprep: A Stringprep Profile for Internationalized Domain Names (IDN)).

See also:

Definition at line 59 of file qurl.h.

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

Generated by  Doxygen 1.6.0   Back to index