QUrl Class Reference

#include <qurl.h>

Collaboration diagram for QUrl:

Collaboration graph
[legend]
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. 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).

See also:
QUrlInfo

Definition at line 39 of file qurl.h.

Public Types

enum  ParsingMode
enum  FormattingOption

Public Member Functions

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

Static Public Member Functions

static QUrl fromLocalFile (const QString &localfile)
static QUrl fromEncoded (const QByteArray &url)
static QUrl fromEncoded (const QByteArray &url, ParsingMode mode)
static QString fromPercentEncoding (const QByteArray &)
static QByteArray toPercentEncoding (const QString &, const QByteArray &exclude=QByteArray(), const QByteArray &include=QByteArray())
static QString fromPunycode (const QByteArray &)
static QByteArray toPunycode (const QString &)
static QString fromAce (const QByteArray &)
static QByteArray toAce (const QString &)
static QStringList idnWhitelist ()
static void setIdnWhitelist (const QStringList &)

Private Attributes

QUrlPrivated

Related Functions

(Note that these are not member functions.)

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


Member Enumeration Documentation

enum QUrl::ParsingMode

The parsing mode controls the way QUrl parses strings.

TolerantMode QUrl will try to correct some common errors in URLs. This mode is useful when processing URLs entered by users.

StrictMode Only valid URLs are accepted. This mode is useful for general URL validation.

In TolerantMode, the parser corrects the following invalid input:

Spaces and "%20": If an encoded URL contains a space, this will be replaced with "%20". If a decoded URL contains "%20", this will be replaced with a single space before the URL is parsed.

Single "%" characters: Any occurrences of a percent character "%" not followed by exactly two hexadecimal characters (e.g., "13% coverage.html") will be replaced by "%25".

Non-US-ASCII characters: An encoded URL should only contain US-ASCII characters. In TolerantMode, characters outside this range are automatically percent-encoded.

Any occurrence of "[" and "]" following the host part of the URL is percent-encoded.

Definition at line 42 of file qurl.h.

00042                      {
00043         TolerantMode,
00044         StrictMode
00045     };

enum QUrl::FormattingOption

The formatting options define how the URL is formatted when written out as text.

None The URL is left unchanged. RemoveScheme The scheme is removed from the URL. RemovePassword Any password in the URL is removed. RemoveUserInfo Any user information in the URL is removed. RemovePort Any specified port is removed from the URL. RemoveAuthority RemovePath The URL's path is removed, leaving only the scheme, host address, and port (if present). RemoveQuery The query part of the URL (following a '?' character) is removed. RemoveFragment StripTrailingSlash The trailing slash is removed if one is present.

Definition at line 48 of file qurl.h.

00048                           {
00049         None = 0x0,
00050         RemoveScheme = 0x1,
00051         RemovePassword = 0x2,
00052         RemoveUserInfo = RemovePassword | 0x4,
00053         RemovePort = 0x8,
00054         RemoveAuthority = RemoveUserInfo | RemovePort | 0x10,
00055         RemovePath = 0x20,
00056         RemoveQuery = 0x40,
00057         RemoveFragment = 0x80,
00058 
00059         StripTrailingSlash = 0x10000
00060     };


Constructor & Destructor Documentation

QUrl::QUrl (  ) 

Constructs an empty QUrl object.

Definition at line 3594 of file qurl.cpp.

03594            : d(new QUrlPrivate)
03595 {
03596 }

QUrl::QUrl ( const QString url  ) 

Constructs a URL by parsing url. url is assumed to be in human readable representation, with no percent encoding. QUrl will automatically percent encode all characters that are not allowed in a URL.

Example:

        QUrl url("http://www.example.com/List of holidays.xml");
        // url.toEncoded() == "http://www.example.com/List of holidays.xml"

To construct a URL from an encoded string, call fromEncoded():

        QUrl url = QUrl::fromEncoded("http://www.trolltech.com/List%20of%20holidays.xml");

See also:
setUrl(), setEncodedUrl(), fromEncoded(), TolerantMode

Definition at line 3570 of file qurl.cpp.

References QString::isEmpty(), and setUrl().

03570                              : d(new QUrlPrivate)
03571 {
03572     if (!url.isEmpty())
03573         setUrl(url);
03574 }

Here is the call graph for this function:

QUrl::QUrl ( const QString url,
ParsingMode  parsingMode 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Parses the url using the parser mode parsingMode.

See also:
setUrl()

Definition at line 3583 of file qurl.cpp.

References d, QString::isEmpty(), QUrlPrivate::parsingMode, and setUrl().

03583                                                       : d(new QUrlPrivate)
03584 {
03585     if (!url.isEmpty())
03586         setUrl(url, parsingMode);
03587     else
03588         d->parsingMode = parsingMode;
03589 }

Here is the call graph for this function:

QUrl::QUrl ( const QUrl other  ) 

Constructs a copy of other.

Definition at line 3601 of file qurl.cpp.

References d, QUrlPrivate::ref, and QBasicAtomic::ref().

03601                             : d(other.d)
03602 {
03603     d->ref.ref();
03604 }

Here is the call graph for this function:

QUrl::~QUrl (  ) 

Destructor; called immediately before the object is deleted.

Definition at line 3609 of file qurl.cpp.

References d, QBasicAtomic::deref(), and QUrlPrivate::ref.

03610 {
03611     if (!d->ref.deref())
03612         delete d;
03613 }

Here is the call graph for this function:


Member Function Documentation

QUrl & QUrl::operator= ( const QUrl url  ) 

Assigns the specified url to this object.

Definition at line 5085 of file qurl.cpp.

References d, and qAtomicAssign().

05086 {
05087     qAtomicAssign(d, url.d);
05088     return *this;
05089 }

Here is the call graph for this function:

QUrl & QUrl::operator= ( const QString url  ) 

Assigns the specified url to this object.

Definition at line 5094 of file qurl.cpp.

References d, and qAtomicAssign().

05095 {
05096     QUrl tmp(url);
05097     qAtomicAssign(d, tmp.d);
05098     return *this;
05099 }

Here is the call graph for this function:

void QUrl::setUrl ( const QString url  ) 

Constructs a URL by parsing the contents of url.

url is assumed to be in unicode format, with no percent encoding.

Calling isValid() will tell whether or not a valid URL was constructed.

See also:
setEncodedUrl()

Definition at line 3681 of file qurl.cpp.

References TolerantMode.

Referenced by QUrl().

03682 {
03683     setUrl(url, TolerantMode);
03684 }

void QUrl::setUrl ( const QString url,
ParsingMode  parsingMode 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Parses url using the parsing mode parsingMode.

See also:
setEncodedUrl()

Definition at line 3693 of file qurl.cpp.

References QString::indexOf(), QString::left(), QString::mid(), QString::replace(), setEncodedUrl(), start, TolerantMode, and toPercentEncoding().

03694 {
03695     // escape all reserved characters and delimiters
03696     // reserved      = gen-delims / sub-delims
03697     if (parsingMode != TolerantMode) {
03698         setEncodedUrl(QUrl::toPercentEncoding(url, ":/?#[]@!$&'()*+,;="), parsingMode);
03699         return;
03700     }
03701 
03702     // Tolerant preprocessing
03703     QString tmp = url;
03704 
03705     // Allow %20 in the QString variant
03706     tmp.replace(QLatin1String("%20"), QLatin1String(" "));
03707     // Replace stray % with %25
03708     tmp.replace(QLatin1String("%([^0-9a-fA-F][^0-9a-fA-F])"), QLatin1String("%25\\1"));
03709 
03710     // Percent-encode unsafe ASCII characters after host part
03711     int start = tmp.indexOf(QLatin1String("//"));
03712     if (start != -1) {
03713         // Has host part, find delimiter
03714         start += 2; // skip "//"
03715         int hostEnd = tmp.indexOf(QLatin1Char('/'), start);
03716         if (hostEnd == -1)
03717             hostEnd = tmp.indexOf(QLatin1Char('#'), start);
03718         if (hostEnd == -1)
03719             hostEnd = tmp.indexOf(QLatin1Char('?'), start);
03720         start = (hostEnd == -1) ? -1 : hostEnd + 1;
03721     } else {
03722         start = 0; // Has no host part
03723     }
03724     QByteArray encodedUrl;
03725     if (start != -1) {
03726         QString hostPart = tmp.left(start);
03727         QString otherPart = tmp.mid(start);
03728         encodedUrl = QUrl::toPercentEncoding(hostPart, ":/?#[]@!$&'()*+,;=")
03729                    + QUrl::toPercentEncoding(otherPart, ":/?#@!$&'()*+,;=");
03730     } else {
03731         encodedUrl = QUrl::toPercentEncoding(tmp, ":/?#[]@!$&'()*+,;=");
03732     }
03733     setEncodedUrl(encodedUrl, parsingMode);
03734 }

Here is the call graph for this function:

void QUrl::setEncodedUrl ( const QByteArray encodedUrl  ) 

Constructs a URL by parsing the contents of encodedUrl.

encodedUrl is assumed to be a URL string in percent encoded form, containing only ASCII characters.

Use isValid() to determine if a valid URL was constructed.

See also:
setUrl()

Definition at line 3746 of file qurl.cpp.

References TolerantMode.

Referenced by fromEncoded(), and setUrl().

03747 {
03748     setEncodedUrl(encodedUrl, TolerantMode);
03749 }

void QUrl::setEncodedUrl ( const QByteArray encodedUrl,
ParsingMode  parsingMode 
)

Constructs a URL by parsing the contents of encodedUrl using the given parsingMode.

Definition at line 3761 of file qurl.cpp.

References QByteArray::append(), buf, clear(), QByteArray::clear(), TokenEngine::copy(), d, QUrlPrivate::encodedOriginal, i, QByteArray::indexOf(), isHex(), QUrlPrivate::parsingMode, qsnprintf(), QByteArray::replace(), start, and TolerantMode.

03762 {
03763     clear();
03764     QByteArray tmp = encodedUrl;
03765     if ((d->parsingMode = parsingMode) == TolerantMode) {
03766         // Allow spaces in the QByteArray variant
03767         tmp.replace(" ", "%20");
03768 
03769         // Replace stray % with %25
03770         QByteArray copy = tmp;
03771         for (int i = 0; i < copy.size(); ++i) {
03772             if (copy.at(i) == '%') {
03773                 if (i + 2 >= copy.size() || !isHex(copy.at(i + 1)) || !isHex(copy.at(i + 2)))
03774                     tmp.replace(i, 1, "%25");
03775             }
03776         }
03777 
03778         // Find the host part
03779         int start = tmp.indexOf("//");
03780         if (start != -1) {
03781             // Has host part, find delimiter
03782             start += 2; // skip "//"
03783             int hostEnd = tmp.indexOf('/', start);
03784             if (hostEnd == -1)
03785                 hostEnd = tmp.indexOf('#', start);
03786             if (hostEnd == -1)
03787                 hostEnd = tmp.indexOf('?');
03788             start = (hostEnd == -1) ? -1 : hostEnd + 1;
03789         } else {
03790             start = 0; // Has no host part
03791         }
03792 
03793         // Replace non-US-ASCII characters with percent encoding
03794         copy = tmp;
03795         tmp.clear();
03796         for (int i = 0; i < copy.size(); ++i) {
03797             quint8 c = quint8(copy.at(i));
03798             if (c < 32 || c > 127 || (start != -1 && i >= start && (c == '[' || c == ']'))) {
03799                 char buf[4];
03800                 qsnprintf(buf, sizeof(buf), "%%%02hX", quint16(c));
03801                 buf[3] = '\0';
03802                 tmp.append(buf);
03803             } else {
03804                 tmp.append(c);
03805             }
03806         }
03807     }
03808 
03809     d->encodedOriginal = tmp;
03810 }

Here is the call graph for this function:

bool QUrl::isValid (  )  const

Returns true if the URL is valid; otherwise returns false.

The URL is run through a conformance test. Every part of the URL must conform to the standard encoding rules of the URI standard for the URL to be reported as valid.

        bool checkUrl(const QUrl &url) {
            if (!url.isValid()) {
                qDebug(QString("Invalid URL: %1").arg(url.toString()));
                return false;
            }

            return true;
        }

Definition at line 3633 of file qurl.cpp.

References d, QUrlPrivate::isValid, QUrlPrivate::parse(), QUrlPrivate::Parsed, QURL_HASFLAG, QUrlPrivate::stateFlags, QUrlPrivate::validate(), and QUrlPrivate::Validated.

Referenced by launchWebBrowser(), MainWindow::on_actionSaveAs_triggered(), openDocument(), QTextBrowserPrivate::setSource(), QTextBrowser::setSource(), MainWindow::showLinks(), and MainWindow::urlifyFileName().

03634 {
03635     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
03636     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Validated)) d->validate();
03637 
03638     return d->isValid;
03639 }

Here is the call graph for this function:

bool QUrl::isEmpty (  )  const

Returns true if the URL has no data; otherwise returns false.

Definition at line 3644 of file qurl.cpp.

References d, QUrlPrivate::encodedOriginal, QUrlPrivate::fragment, QUrlPrivate::host, QByteArray::isEmpty(), QString::isEmpty(), QUrlPrivate::Parsed, QUrlPrivate::password, QUrlPrivate::path, QUrlPrivate::port, QUrlPrivate::query, QURL_HASFLAG, QUrlPrivate::scheme, QUrlPrivate::stateFlags, and QUrlPrivate::userName.

03645 {
03646     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed))
03647         return d->encodedOriginal.isEmpty();
03648     else
03649         return d->scheme.isEmpty()
03650         && d->userName.isEmpty()
03651         && d->password.isEmpty()
03652         && d->host.isEmpty()
03653         && d->port == -1
03654         && d->path.isEmpty()
03655         && d->query.isEmpty()
03656         && d->fragment.isEmpty();
03657 }

Here is the call graph for this function:

void QUrl::clear (  ) 

Resets the content of the QUrl. After calling this function, the QUrl is equal to one that has been constructed with the default empty constructor.

Definition at line 3664 of file qurl.cpp.

References QUrlPrivate::clear(), d, and detach().

Referenced by setEncodedUrl().

03665 {
03666     detach();
03667     d->clear();
03668 }

Here is the call graph for this function:

void QUrl::setScheme ( const QString scheme  ) 

Sets the scheme of the URL to scheme. As a scheme can only contain ASCII characters, no conversion or encoding is done on the input.

The scheme describes the type (or protocol) of the URL. It's represented by one or more ASCII characters at the start the URL, and is followed by a ':'. The following example shows a URL where the scheme is "ftp":

qurl-authority2.png

The scheme can also be empty, in which case the URL is interpreted as relative.

See also:
scheme(), isRelative()

Definition at line 3829 of file qurl.cpp.

References d, detach(), QUrlPrivate::Normalized, QUrlPrivate::parse(), QUrlPrivate::Parsed, QURL_HASFLAG, QURL_UNSETFLAG, QUrlPrivate::scheme, scheme(), QUrlPrivate::stateFlags, and QUrlPrivate::Validated.

Referenced by fromLocalFile().

Here is the call graph for this function:

QString QUrl::scheme (  )  const

Returns the scheme of the URL. If an empty string is returned, this means the scheme is undefined and the URL is then relative.

See also:
setScheme(), isRelative()

Definition at line 3844 of file qurl.cpp.

References d, QUrlPrivate::parse(), QUrlPrivate::Parsed, QURL_HASFLAG, QUrlPrivate::scheme, and QUrlPrivate::stateFlags.

Referenced by QTextBrowserPrivate::_q_activateAnchor(), isParentOf(), launchWebBrowser(), QDesktopServices::openUrl(), setScheme(), FeatureTextBrowser::setSource(), and MainWindow::urlifyFileName().

03845 {
03846     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
03847 
03848     return d->scheme;
03849 }

Here is the call graph for this function:

void QUrl::setAuthority ( const QString authority  ) 

Sets the authority of the URL to authority.

The authority of a URL is the combination of user info, a host name and a port. All of these elements are optional; an empty authority is therefore valid.

The user info and host are separated by a '@', and the host and port are separated by a ':'. If the user info is empty, the '@' must be omitted; although a stray ':' is permitted if the port is empty.

The following example shows a valid authority string:

qurl-authority.png

Definition at line 3867 of file qurl.cpp.

References authority(), d, detach(), QUrlPrivate::Normalized, QUrlPrivate::parse(), QUrlPrivate::Parsed, QURL_HASFLAG, QURL_UNSETFLAG, QUrlPrivate::setAuthority(), QUrlPrivate::stateFlags, and QUrlPrivate::Validated.

Here is the call graph for this function:

QString QUrl::authority (  )  const

Returns the authority of the URL if it is defined; otherwise an empty string is returned.

See also:
setAuthority()

Definition at line 3882 of file qurl.cpp.

References QUrlPrivate::authority(), d, QUrlPrivate::parse(), QUrlPrivate::Parsed, QURL_HASFLAG, and QUrlPrivate::stateFlags.

Referenced by isParentOf(), setAuthority(), and FeatureTextBrowser::setSource().

03883 {
03884     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
03885 
03886     return d->authority();
03887 }

Here is the call graph for this function:

void QUrl::setUserInfo ( const QString userInfo  ) 

Sets the user info of the URL to userInfo. The user info is an optional part of the authority of the URL, as described in setAuthority().

The user info consists of a user name and optionally a password, separated by a ':'. If the password is empty, the colon must be omitted. The following example shows a valid user info string:

qurl-authority3.png

See also:
userInfo(), setUserName(), setPassword(), setAuthority()

Definition at line 3902 of file qurl.cpp.

References d, detach(), QUrlPrivate::Normalized, QUrlPrivate::parse(), QUrlPrivate::Parsed, QURL_HASFLAG, QURL_UNSETFLAG, QUrlPrivate::setUserInfo(), QUrlPrivate::stateFlags, QString::trimmed(), userInfo(), and QUrlPrivate::Validated.

Here is the call graph for this function:

QString QUrl::userInfo (  )  const

Returns the user info of the URL, or an empty string if the user info is undefined.

Definition at line 3915 of file qurl.cpp.

References d, QUrlPrivate::parse(), QUrlPrivate::Parsed, QURL_HASFLAG, QUrlPrivate::stateFlags, and QUrlPrivate::userInfo().

Referenced by setUserInfo().

03916 {
03917     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
03918 
03919     return d->userInfo();
03920 }

Here is the call graph for this function:

void QUrl::setUserName ( const QString userName  ) 

Sets the URL's user name to userName. The userName is part of the user info element in the authority of the URL, as described in setUserInfo().

See also:
userName(), setUserInfo()

Definition at line 3929 of file qurl.cpp.

References d, detach(), QUrlPrivate::Normalized, QUrlPrivate::parse(), QUrlPrivate::Parsed, QURL_HASFLAG, QURL_UNSETFLAG, QUrlPrivate::stateFlags, QUrlPrivate::userName, userName(), and QUrlPrivate::Validated.

Here is the call graph for this function:

QString QUrl::userName (  )  const

Returns the user name of the URL if it is defined; otherwise an empty string is returned.

See also:
setUserName()

Definition at line 3944 of file qurl.cpp.

References d, QUrlPrivate::parse(), QUrlPrivate::Parsed, QURL_HASFLAG, QUrlPrivate::stateFlags, and QUrlPrivate::userName.

Referenced by setUserName().

03945 {
03946     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
03947 
03948     return d->userName;
03949 }

Here is the call graph for this function:

void QUrl::setPassword ( const QString password  ) 

Sets the URL's password to password. The password is part of the user info element in the authority of the URL, as described in setUserInfo().

See also:
password(), setUserInfo()

Definition at line 3958 of file qurl.cpp.

References d, detach(), QUrlPrivate::Normalized, QUrlPrivate::parse(), QUrlPrivate::Parsed, QUrlPrivate::password, password(), QURL_HASFLAG, QURL_UNSETFLAG, QUrlPrivate::stateFlags, and QUrlPrivate::Validated.

Here is the call graph for this function:

QString QUrl::password (  )  const

Returns the password of the URL if it is defined; otherwise an empty string is returned.

See also:
setUserName()

Definition at line 3973 of file qurl.cpp.

References d, QUrlPrivate::parse(), QUrlPrivate::Parsed, QUrlPrivate::password, QURL_HASFLAG, and QUrlPrivate::stateFlags.

Referenced by setPassword().

03974 {
03975     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
03976 
03977     return d->password;
03978 }

Here is the call graph for this function:

void QUrl::setHost ( const QString host  ) 

Sets the host of the URL to host. The host is part of the authority.

See also:
host(), setAuthority()

Definition at line 3986 of file qurl.cpp.

References QString::contains(), d, detach(), QUrlPrivate::host, host(), QUrlPrivate::Normalized, QUrlPrivate::parse(), QUrlPrivate::Parsed, qt_nameprep(), QURL_HASFLAG, QURL_UNSETFLAG, QUrlPrivate::stateFlags, QString::trimmed(), and QUrlPrivate::Validated.

Referenced by QHttpPrivate::_q_slotSendRequest(), and fromLocalFile().

03987 {
03988     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
03989     detach();
03990     QURL_UNSETFLAG(d->stateFlags, QUrlPrivate::Validated | QUrlPrivate::Normalized);
03991 
03992     d->host = qt_nameprep(host.trimmed());
03993     if (d->host.contains(QLatin1Char(':')))
03994         d->host = QLatin1Char('[') + d->host + QLatin1Char(']');
03995 }

Here is the call graph for this function:

QString QUrl::host (  )  const

Returns the host of the URL if it is defined; otherwise an empty string is returned.

Definition at line 4001 of file qurl.cpp.

References QString::at(), d, QUrlPrivate::host, QString::isEmpty(), QString::mid(), QUrlPrivate::parse(), QUrlPrivate::Parsed, QURL_HASFLAG, QUrlPrivate::stateFlags, and QString::truncate().

Referenced by setHost().

04002 {
04003     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
04004 
04005     if (d->host.isEmpty() || d->host.at(0) != QLatin1Char('['))
04006         return d->host;
04007     QString tmp = d->host.mid(1);
04008     tmp.truncate(tmp.length() - 1);
04009     return tmp;
04010 }

Here is the call graph for this function:

void QUrl::setPort ( int  port  ) 

Sets the port of the URL to port. The port is part of the authority of the URL, as described in setAuthority().

port must be between 0 and 65535 inclusive. Setting the port to -1 indicates that the port is unspecified.

Definition at line 4019 of file qurl.cpp.

References d, detach(), QUrlPrivate::Normalized, QUrlPrivate::parse(), QUrlPrivate::Parsed, QUrlPrivate::port, QURL_HASFLAG, QURL_UNSETFLAG, qWarning(), QUrlPrivate::stateFlags, and QUrlPrivate::Validated.

Referenced by QHttpPrivate::_q_slotSendRequest().

04020 {
04021     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
04022     detach();
04023     QURL_UNSETFLAG(d->stateFlags, QUrlPrivate::Validated | QUrlPrivate::Normalized);
04024 
04025     if (port < -1 || port > 65535) {
04026         qWarning("QUrl::setPort: Out of range");
04027         port = -1;
04028     }
04029 
04030     d->port = port;
04031 }

Here is the call graph for this function:

int QUrl::port (  )  const

Returns the port of the URL, or -1 if the port is unspecified.

Definition at line 4036 of file qurl.cpp.

References d, QUrlPrivate::parse(), QUrlPrivate::Parsed, QUrlPrivate::port, QURL_HASFLAG, QUrlPrivate::stateFlags, QUrlPrivate::validate(), and QUrlPrivate::Validated.

04037 {
04038     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
04039     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Validated)) d->validate();
04040     return d->port;
04041 }

Here is the call graph for this function:

int QUrl::port ( int  defaultPort  )  const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since:
4.1
Returns the port of the URL, or defaultPort if the port is unspecified.

Example:

        QFtp ftp;
        ftp.connectToHost(url.host(), url.port(21));

Definition at line 4057 of file qurl.cpp.

References d, QUrlPrivate::parse(), QUrlPrivate::Parsed, QUrlPrivate::port, QURL_HASFLAG, and QUrlPrivate::stateFlags.

04058 {
04059     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
04060     return d->port == -1 ? defaultPort : d->port;
04061 }

Here is the call graph for this function:

void QUrl::setPath ( const QString path  ) 

Sets the path of the URL to path. The path is the part of the URL that comes after the authority but before the query string.

qurl-ftppath.png

For non-hierarchical schemes, the path will be everything following the scheme declaration, as in the following example:

qurl-mailtopath.png

See also:
path()

Definition at line 4076 of file qurl.cpp.

References d, detach(), QUrlPrivate::Normalized, QUrlPrivate::parse(), QUrlPrivate::Parsed, path(), QUrlPrivate::path, QURL_HASFLAG, QURL_UNSETFLAG, QUrlPrivate::stateFlags, and QUrlPrivate::Validated.

Referenced by fromLocalFile().

Here is the call graph for this function:

QString QUrl::path (  )  const

Returns the path of the URL.

See also:
setPath()

Definition at line 4090 of file qurl.cpp.

References d, QUrlPrivate::parse(), QUrlPrivate::Parsed, QUrlPrivate::path, QURL_HASFLAG, and QUrlPrivate::stateFlags.

Referenced by QTextBrowserPrivate::_q_documentModified(), isParentOf(), QUrlInfo::QUrlInfo(), QTextBrowserPrivate::resolveUrl(), and setPath().

04091 {
04092     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
04093 
04094     return d->path;
04095 }

Here is the call graph for this function:

bool QUrl::hasQuery (  )  const

Since:
4.2
Returns true if this URL contains a Query (i.e., if ? was seen on it).

See also:
hasQueryItem(), encodedQuery()

Definition at line 4104 of file qurl.cpp.

References d, QUrlPrivate::hasQuery, QUrlPrivate::parse(), QUrlPrivate::Parsed, QURL_HASFLAG, and QUrlPrivate::stateFlags.

04105 {
04106     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
04107 
04108     return d->hasQuery;
04109 }

Here is the call graph for this function:

void QUrl::setEncodedQuery ( const QByteArray query  ) 

Sets the query string of the URL to query. The string is inserted as-is, and no further encoding is performed when calling toEncoded().

This function is useful if you need to pass a query string that does not fit into the key-value pattern, or that uses a different scheme for encoding special characters than what is suggested by QUrl.

Passing a value of QByteArray() to query (a null QByteArray) unsets the query completely. However, passing a value of QByteArray("") will set the query to an empty value, as if the original URL had a lone "?".

See also:
encodedQuery(), hasQuery()

Definition at line 4178 of file qurl.cpp.

References d, detach(), QUrlPrivate::hasQuery, QByteArray::isNull(), QUrlPrivate::Normalized, QUrlPrivate::parse(), QUrlPrivate::Parsed, QUrlPrivate::query, QURL_HASFLAG, QURL_UNSETFLAG, QUrlPrivate::stateFlags, and QUrlPrivate::Validated.

04179 {
04180     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
04181     detach();
04182     QURL_UNSETFLAG(d->stateFlags, QUrlPrivate::Validated | QUrlPrivate::Normalized);
04183 
04184     d->query = query;
04185     d->hasQuery = !query.isNull();
04186 }

Here is the call graph for this function:

QByteArray QUrl::encodedQuery (  )  const

Returns the query string of the URL in percent encoded form.

Definition at line 4388 of file qurl.cpp.

References d, QUrlPrivate::parse(), QUrlPrivate::Parsed, QUrlPrivate::query, QURL_HASFLAG, and QUrlPrivate::stateFlags.

04389 {
04390     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
04391 
04392     return d->query;
04393 }

Here is the call graph for this function:

void QUrl::setQueryDelimiters ( char  valueDelimiter,
char  pairDelimiter 
)

Sets the characters used for delimiting between keys and values, and between key-value pairs in the URL's query string. The default value delimiter is '=' and the default pair delimiter is '&'.

qurl-querystring.png

valueDelimiter will be used for separating keys from values, and pairDelimiter will be used to separate key-value pairs. Any occurrences of these delimiting characters in the encoded representation of the keys and values of the query string are percent encoded.

If valueDelimiter is set to '-' and pairDelimiter is '/', the above query string would instead be represented like this:

        http://www.example.com/cgi-bin/drawgraph.cgi?type-pie/color-green

Calling this function does not change the delimiters of the current query string. It only affects queryItems(), setQueryItems() and addQueryItems().

Definition at line 4135 of file qurl.cpp.

References d, detach(), QUrlPrivate::pairDelimiter, and QUrlPrivate::valueDelimiter.

04136 {
04137     detach();
04138 
04139     d->valueDelimiter = valueDelimiter;
04140     d->pairDelimiter = pairDelimiter;
04141 }

Here is the call graph for this function:

char QUrl::queryValueDelimiter (  )  const

Returns the character used to delimit between keys and values in the query string of the URL.

Definition at line 4156 of file qurl.cpp.

References d, and QUrlPrivate::valueDelimiter.

04157 {
04158     return d->valueDelimiter;
04159 }

char QUrl::queryPairDelimiter (  )  const

Returns the character used to delimit between key-value pairs in the query string of the URL.

Definition at line 4147 of file qurl.cpp.

References d, and QUrlPrivate::pairDelimiter.

04148 {
04149     return d->pairDelimiter;
04150 }

void QUrl::setQueryItems ( const QList< QPair< QString, QString > > &  query  ) 

Sets the query string of the URL to an encoded version of query. The contents of query are converted to a string internally, each pair delimited by the character returned by pairDelimiter(), and the key and value are delimited by valueDelimiter().

See also:
setQueryDelimiters(), queryItems()

Definition at line 4197 of file qurl.cpp.

References d, detach(), QUrlPrivate::hasQuery, i, QUrlPrivate::pairDelimiter, QUrlPrivate::parse(), QUrlPrivate::Parsed, QUrlPrivate::query, QURL_HASFLAG, QUrlPrivate::stateFlags, toPercentEncoding(), and QUrlPrivate::valueDelimiter.

Referenced by removeAllQueryItems(), and removeQueryItem().

04198 {
04199     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
04200     detach();
04201 
04202     QByteArray alsoEncode;
04203     alsoEncode += d->valueDelimiter;
04204     alsoEncode += d->pairDelimiter;
04205 
04206     QByteArray queryTmp;
04207     for (int i = 0; i < query.size(); i++) {
04208         if (i) queryTmp += d->pairDelimiter;
04209         // query = *( pchar / "/" / "?" )
04210         queryTmp += QUrl::toPercentEncoding(query.at(i).first, "!$&'()*+,;=:@/?", alsoEncode);
04211         queryTmp += d->valueDelimiter;
04212         // query = *( pchar / "/" / "?" )
04213         queryTmp += QUrl::toPercentEncoding(query.at(i).second, "!$&'()*+,;=:@/?", alsoEncode);
04214     }
04215 
04216     d->query = queryTmp;
04217     d->hasQuery = !query.isEmpty();
04218 }

Here is the call graph for this function:

void QUrl::addQueryItem ( const QString key,
const QString value 
)

Inserts the pair key = value into the query string of the URL.

Definition at line 4224 of file qurl.cpp.

References d, detach(), QUrlPrivate::hasQuery, QByteArray::isEmpty(), key, QUrlPrivate::pairDelimiter, QUrlPrivate::parse(), QUrlPrivate::Parsed, QUrlPrivate::query, QURL_HASFLAG, QUrlPrivate::stateFlags, toPercentEncoding(), value, and QUrlPrivate::valueDelimiter.

04225 {
04226     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
04227     detach();
04228 
04229     QByteArray alsoEncode;
04230     alsoEncode += d->valueDelimiter;
04231     alsoEncode += d->pairDelimiter;
04232 
04233     if (!d->query.isEmpty())
04234         d->query += d->pairDelimiter;
04235 
04236     // query = *( pchar / "/" / "?" )
04237     d->query += QUrl::toPercentEncoding(key, "!$&'()*+,;=:@/?", alsoEncode);
04238     d->query += d->valueDelimiter;
04239     // query = *( pchar / "/" / "?" )
04240     d->query += QUrl::toPercentEncoding(value, "!$&'()*+,;=:@/?", alsoEncode);
04241 
04242     d->hasQuery = !d->query.isEmpty();
04243 }

Here is the call graph for this function:

QList< QPair< QString, QString > > QUrl::queryItems (  )  const

Returns the query string of the URL, as a map of keys and values.

See also:
setQueryItems(), setEncodedQuery()

Definition at line 4250 of file qurl.cpp.

References QList< T >::at(), d, fromPercentEncoding(), i, QByteArray::isEmpty(), QUrlPrivate::pairDelimiter, QUrlPrivate::parse(), QUrlPrivate::Parsed, qMakePair(), QUrlPrivate::query, QURL_HASFLAG, QByteArray::split(), QUrlPrivate::stateFlags, and QUrlPrivate::valueDelimiter.

Referenced by allQueryItemValues(), hasQueryItem(), queryItemValue(), removeAllQueryItems(), and removeQueryItem().

04251 {
04252     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
04253 
04254     QList<QPair<QString, QString> > itemMap;
04255 
04256     if (!d->query.isEmpty()) {
04257         QList<QByteArray> items = d->query.split(d->pairDelimiter);
04258         for (int i = 0; i < items.count(); ++i) {
04259             QList<QByteArray> keyValuePair = items.at(i).split(d->valueDelimiter);
04260             if (keyValuePair.size() == 1) {
04261                 itemMap += qMakePair(QString(QUrl::fromPercentEncoding(
04262                                      keyValuePair.at(0))).replace('+', ' '),
04263                                      QString());
04264             } else if (keyValuePair.size() == 2) {
04265                 itemMap += qMakePair(QString(QUrl::fromPercentEncoding(
04266                                      keyValuePair.at(0))).replace('+', ' '),
04267                                      QString(QUrl::fromPercentEncoding(
04268                                      keyValuePair.at(1))).replace('+', ' '));
04269             }
04270         }
04271     }
04272 
04273     return itemMap;
04274 }

Here is the call graph for this function:

bool QUrl::hasQueryItem ( const QString key  )  const

Returns true if there is a query string pair whose key is equal to key from the URL.

Definition at line 4280 of file qurl.cpp.

References QList< T >::constBegin(), QList< T >::constEnd(), d, key, QUrlPrivate::parse(), QUrlPrivate::Parsed, queryItems(), QURL_HASFLAG, and QUrlPrivate::stateFlags.

04281 {
04282     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
04283 
04284     QList<QPair<QString, QString> > items = queryItems();
04285     QList<QPair<QString, QString> >::ConstIterator it = items.constBegin();
04286     while (it != items.constEnd()) {
04287         if ((*it).first == key)
04288             return true;
04289         ++it;
04290     }
04291 
04292     return false;
04293 }

Here is the call graph for this function:

QString QUrl::queryItemValue ( const QString key  )  const

Returns the first query string value whose key is equal to key from the URL.

See also:
allQueryItemValues()

Definition at line 4301 of file qurl.cpp.

References QList< T >::constBegin(), QList< T >::constEnd(), d, key, QUrlPrivate::parse(), QUrlPrivate::Parsed, queryItems(), QURL_HASFLAG, and QUrlPrivate::stateFlags.

04302 {
04303     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
04304 
04305     QList<QPair<QString, QString> > items = queryItems();
04306     QList<QPair<QString, QString> >::ConstIterator it = items.constBegin();
04307     while (it != items.constEnd()) {
04308         if ((*it).first == key)
04309             return (*it).second;
04310         ++it;
04311     }
04312 
04313     return QString();
04314 }

Here is the call graph for this function:

QStringList QUrl::allQueryItemValues ( const QString key  )  const

Returns the a list of query string values whose key is equal to key from the URL.

See also:
queryItemValue()

Definition at line 4322 of file qurl.cpp.

References QList< T >::constBegin(), QList< T >::constEnd(), d, key, QUrlPrivate::parse(), QUrlPrivate::Parsed, queryItems(), QURL_HASFLAG, QUrlPrivate::stateFlags, and values.

04323 {
04324     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
04325 
04326     QStringList values;
04327 
04328     QList<QPair<QString, QString> > items = queryItems();
04329     QList<QPair<QString, QString> >::ConstIterator it = items.constBegin();
04330     while (it != items.constEnd()) {
04331         if ((*it).first == key)
04332             values += (*it).second;
04333         ++it;
04334     }
04335 
04336     return values;
04337 }

Here is the call graph for this function:

void QUrl::removeQueryItem ( const QString key  ) 

Removes the first query string pair whose key is equal to key from the URL.

See also:
removeAllQueryItems()

Definition at line 4345 of file qurl.cpp.

References QList< T >::begin(), d, detach(), QList< T >::end(), QList< T >::erase(), key, QUrlPrivate::parse(), QUrlPrivate::Parsed, queryItems(), QURL_HASFLAG, setQueryItems(), and QUrlPrivate::stateFlags.

04346 {
04347     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
04348     detach();
04349 
04350     QList<QPair<QString, QString> > items = queryItems();
04351     QList<QPair<QString, QString> >::Iterator it = items.begin();
04352     while (it != items.end()) {
04353         if ((*it).first == key) {
04354             items.erase(it);
04355             break;
04356         }
04357         ++it;
04358     }
04359     setQueryItems(items);
04360 }

Here is the call graph for this function:

void QUrl::removeAllQueryItems ( const QString key  ) 

Removes all the query string pairs whose key is equal to key from the URL.

See also:
removeQueryItem()

Definition at line 4368 of file qurl.cpp.

References QList< T >::begin(), d, detach(), QList< T >::end(), QList< T >::erase(), key, QUrlPrivate::parse(), QUrlPrivate::Parsed, queryItems(), QURL_HASFLAG, setQueryItems(), and QUrlPrivate::stateFlags.

04369 {
04370     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
04371     detach();
04372 
04373     QList<QPair<QString, QString> > items = queryItems();
04374     QList<QPair<QString, QString> >::Iterator it = items.begin();
04375     while (it != items.end()) {
04376         if ((*it).first == key) {
04377             it = items.erase(it);
04378             continue;
04379         }
04380         ++it;
04381     }
04382     setQueryItems(items);
04383 }

Here is the call graph for this function:

void QUrl::setFragment ( const QString fragment  ) 

Sets the fragment of the URL to fragment. The fragment is the last part of the URL, represented by a '#' followed by a string of characters. It is typically used in HTTP for referring to a certain link or point on a page:

qurl-fragment.png

The fragment is sometimes also referred to as the URL "reference".

Passing an argument of QString() (a null QString) will unset the fragment. Passing an argument of QString("") (an empty but not null QString) will set the fragment to an empty string (as if the original URL had a lone "#").

See also:
fragment(), hasFragment()

Definition at line 4412 of file qurl.cpp.

References d, detach(), QUrlPrivate::fragment, fragment(), QUrlPrivate::hasFragment, QString::isNull(), QUrlPrivate::Normalized, QUrlPrivate::parse(), QUrlPrivate::Parsed, QURL_HASFLAG, QURL_UNSETFLAG, QUrlPrivate::stateFlags, and QUrlPrivate::Validated.

Referenced by QTextBrowserPrivate::setSource().

Here is the call graph for this function:

QString QUrl::fragment (  )  const

Returns the fragment of the URL.

See also:
setFragment()

Definition at line 4427 of file qurl.cpp.

References d, QUrlPrivate::fragment, QUrlPrivate::parse(), QUrlPrivate::Parsed, QURL_HASFLAG, and QUrlPrivate::stateFlags.

Referenced by setFragment(), and QTextBrowserPrivate::setSource().

04428 {
04429     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
04430 
04431     return d->fragment;
04432 }

Here is the call graph for this function:

bool QUrl::hasFragment (  )  const

Since:
4.2
Returns true if this URL contains a fragment (i.e., if # was seen on it).

See also:
fragment(), setFragment()

Definition at line 4441 of file qurl.cpp.

References d, QUrlPrivate::hasFragment, QUrlPrivate::parse(), QUrlPrivate::Parsed, QURL_HASFLAG, and QUrlPrivate::stateFlags.

Referenced by QTextBrowserPrivate::resolveUrl().

04442 {
04443     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
04444 
04445     return d->hasFragment;
04446 }

Here is the call graph for this function:

QUrl QUrl::resolved ( const QUrl relative  )  const

Returns the result of the merge of this URL with relative. This URL is used as a base to convert relative to an absolute URL.

If relative is not a relative URL, this function will return relative directly. Otherwise, the paths of the two URLs are merged, and the new URL returned has the scheme and authority of the base URL, but with the merged path, as in the following example:

         QUrl baseUrl("http://www.trolltech.com/support");
         QUrl relativeUrl("../products/solutions");
         qDebug(baseUrl.resolved(relativeUrl).toString());
         // prints "http://www.trolltech.com/products/solutions"

Calling resolved() with ".." returns a QUrl whose directory is one level higher than the original. Similarly, calling resolved() with "../.." removes two levels from the path. If relative is "/", the path becomes "/".

See also:
isRelative()

Definition at line 4472 of file qurl.cpp.

References QUrlPrivate::authority(), d, QUrlPrivate::mergePaths(), QUrlPrivate::parse(), QUrlPrivate::Parsed, QUrlPrivate::path, QUrlPrivate::query, QURL_HASFLAG, QUrlPrivate::removeDotsFromPath(), QUrlPrivate::scheme, QUrlPrivate::stateFlags, and t.

Referenced by QHttpPrivate::_q_slotSendRequest(), HelpWindow::hasAnchorAt(), MainWindow::on_actionSaveAs_triggered(), QTextBrowserPrivate::resolveUrl(), and QTextBrowserPrivate::setSource().

04473 {
04474     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
04475 
04476     QUrl r(relative), t;
04477 
04478     // be non strict and allow scheme in relative url
04479     if (r.scheme() == d->scheme)
04480         r.setScheme(QString());
04481 
04482     if (!r.scheme().isEmpty()) {
04483         t.setScheme(r.scheme());
04484         t.setAuthority(r.authority());
04485         t.setPath(r.path());
04486         t.d->path = QUrlPrivate::removeDotsFromPath(t.d->path);
04487         t.setEncodedQuery(r.encodedQuery());
04488     } else {
04489         if (!r.authority().isEmpty()) {
04490             t.setAuthority(r.authority());
04491             t.setPath(r.path());
04492             t.d->path = QUrlPrivate::removeDotsFromPath(t.d->path);
04493             t.setEncodedQuery(r.encodedQuery());
04494         } else {
04495             if (r.path().isEmpty()) {
04496                 t.setPath(d->path);
04497                 if (!r.encodedQuery().isEmpty())
04498                     t.setEncodedQuery(r.encodedQuery());
04499                 else
04500                     t.setEncodedQuery(d->query);
04501             } else {
04502                 if (r.path().startsWith(QLatin1Char('/'))) {
04503                     t.setPath(r.path());
04504                     t.d->path = QUrlPrivate::removeDotsFromPath(t.d->path);
04505                 } else {
04506                     t.setPath(d->mergePaths(r.path()));
04507                     t.d->path = QUrlPrivate::removeDotsFromPath(t.d->path);
04508                 }
04509                 t.setEncodedQuery(r.encodedQuery());
04510             }
04511             t.setAuthority(d->authority());
04512         }
04513         t.setScheme(d->scheme);
04514     }
04515     t.setFragment(r.fragment());
04516 
04517     return t;
04518 }

Here is the call graph for this function:

bool QUrl::isRelative (  )  const

Returns true if the URL is relative; otherwise returns false. A URL is relative if its scheme is undefined; this function is therefore equivalent to calling scheme().isEmpty().

Definition at line 4525 of file qurl.cpp.

References d, QString::isEmpty(), QUrlPrivate::parse(), QUrlPrivate::Parsed, QURL_HASFLAG, QUrlPrivate::scheme, and QUrlPrivate::stateFlags.

Referenced by QTextBrowserPrivate::resolveUrl().

04526 {
04527     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
04528 
04529     return d->scheme.isEmpty();
04530 }

Here is the call graph for this function:

bool QUrl::isParentOf ( const QUrl childUrl  )  const

Returns true if this URL is a parent of childUrl. childUrl is a child of this URL if the two URLs share the same scheme and authority, and this URL's path is a parent of the path of childUrl.

Definition at line 5176 of file qurl.cpp.

References QString::at(), QUrlPrivate::authority(), authority(), d, QString::endsWith(), QString::isEmpty(), QString::length(), QUrlPrivate::parse(), QUrlPrivate::Parsed, path(), QUrlPrivate::path, QURL_HASFLAG, QUrlPrivate::scheme, scheme(), QString::startsWith(), and QUrlPrivate::stateFlags.

05177 {
05178     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
05179 
05180     QString childPath = childUrl.path();
05181 
05182     return ((childUrl.scheme().isEmpty() || d->scheme == childUrl.scheme())
05183             && (childUrl.authority().isEmpty() || d->authority() == childUrl.authority())
05184             &&  childPath.startsWith(d->path)
05185             && ((d->path.endsWith(QLatin1Char('/')) && childPath.length() > d->path.length())
05186                 || (!d->path.endsWith(QLatin1Char('/'))
05187                     && childPath.length() > d->path.length() && childPath.at(d->path.length()) == QLatin1Char('/'))));
05188 }

Here is the call graph for this function:

QUrl QUrl::fromLocalFile ( const QString localFile  )  [static]

Returns a QUrl representation of localFile, interpreted as a local file.

Definition at line 5121 of file qurl.cpp.

References QString::at(), QString::indexOf(), QString::length(), QString::mid(), QString::replace(), QString::right(), setHost(), setPath(), setScheme(), and QString::startsWith().

Referenced by QDirModel::mimeData(), and QTextBrowserPrivate::resolveUrl().

05122 {
05123     QUrl url;
05124     url.setScheme(QLatin1String("file"));
05125     QString deslashified = localFile;
05126     deslashified.replace(QLatin1Char('\\'), QLatin1Char('/'));
05127 
05128 
05129 
05130     // magic for drives on windows
05131     if (deslashified.length() > 1 && deslashified.at(1) == QLatin1Char(':') && deslashified.at(0) != QLatin1Char('/')) {
05132         url.setPath(QLatin1String("/") + deslashified);
05133     // magic for shared drive on windows
05134     } else if (deslashified.startsWith(QLatin1String("//"))) {
05135         int indexOfPath = deslashified.indexOf(QLatin1Char('/'), 2);
05136         url.setHost(deslashified.mid(2, indexOfPath - 2));
05137         if (indexOfPath > 2)
05138             url.setPath(deslashified.right(deslashified.length() - indexOfPath));
05139     } else {
05140         url.setPath(deslashified);
05141     }
05142 
05143     return url;
05144 }

Here is the call graph for this function:

QString QUrl::toLocalFile (  )  const

Returns the path of this URL formatted as a local file path.

Definition at line 5149 of file qurl.cpp.

References QString::at(), d, QUrlPrivate::host, QString::isEmpty(), QString::length(), QUrlPrivate::parse(), QUrlPrivate::Parsed, QUrlPrivate::path, QURL_HASFLAG, QString::remove(), QUrlPrivate::scheme, QUrlPrivate::stateFlags, and QString::toLower().

Referenced by Index::getDocumentTitle(), Index::makeIndex(), MainWindow::on_actionSaveAs_triggered(), QTextBrowserPrivate::resolveUrl(), Index::searchForPattern(), and MainWindow::showLink().

05150 {
05151     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
05152 
05153     QString tmp;
05154     if (d->scheme.isEmpty() || d->scheme.toLower() == QLatin1String("file")) {
05155 
05156         // magic for shared drive on windows
05157         if (!d->host.isEmpty()) {
05158             tmp = QLatin1String("//") + d->host + (d->path.length() > 0 && d->path.at(0) != QLatin1Char('/')
05159                                                   ? QLatin1String("/") + d->path :  d->path);
05160         } else {
05161             tmp = d->path;
05162             // magic for drives on windows
05163             if (d->path.length() > 2 && d->path.at(0) == QLatin1Char('/') && d->path.at(2) == QLatin1Char(':'))
05164                 tmp.remove(0, 1);
05165         }
05166     }
05167 
05168     return tmp;
05169 }

Here is the call graph for this function:

QString QUrl::toString ( FormattingOptions  options = None  )  const

Returns the human-displayable string representation of the URL. The output can be customized by passing flags with options.

See also:
FormattingOptions, toEncoded()

Definition at line 4539 of file qurl.cpp.

References QString::at(), QUrlPrivate::authority(), QString::chop(), d, QUrlPrivate::fragment, fromPercentEncoding(), QUrlPrivate::hasFragment, QUrlPrivate::hasQuery, QString::isEmpty(), QUrlPrivate::parse(), QUrlPrivate::Parsed, QUrlPrivate::path, QUrlPrivate::query, QURL_HASFLAG, RemoveAuthority, RemoveFragment, RemovePath, RemoveQuery, RemoveScheme, QString::right(), QUrlPrivate::scheme, QString::startsWith(), QUrlPrivate::stateFlags, and StripTrailingSlash.

Referenced by QTextBrowserPrivate::_q_highlightLink(), HelpDialog::addBookmark(), QAbstractFormBuilder::createProperty(), getPixmap(), HelpWindow::hasAnchorAt(), operator<<(), MainWindow::saveSettings(), QTextBrowserPrivate::setSource(), MainWindow::showLink(), qdesigner_internal::UrlProperty::toString(), and qdesigner_internal::UrlProperty::updateEditorContents().

04540 {
04541     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
04542 
04543     QString url;
04544 
04545     if (!(options & QUrl::RemoveScheme) && !d->scheme.isEmpty())
04546         url += d->scheme + QLatin1Char(':');
04547     if ((options & QUrl::RemoveAuthority) != QUrl::RemoveAuthority) {
04548 
04549         bool doFileScheme = d->scheme == QLatin1String("file") && !d->path.isEmpty();
04550          QString tmp = d->authority(options);
04551         if (!tmp.isEmpty() || doFileScheme) {
04552             if (doFileScheme && !d->path.startsWith(QLatin1Char('/')))
04553                 url += QLatin1Char('/');
04554             url += QLatin1String("//");
04555             url += tmp;
04556         }
04557     }
04558     if (!(options & QUrl::RemovePath)) {
04559         // check if we need to insert a slash
04560         if ((options & QUrl::RemoveAuthority) != QUrl::RemoveAuthority
04561             && !d->authority(options).isEmpty() && !d->path.isEmpty() && d->path.at(0) != QLatin1Char('/'))
04562             url += QLatin1Char('/');
04563         url += d->path;
04564         // check if we need to remove trailing slashes
04565         while ((options & StripTrailingSlash) && url.right(1) == QLatin1String("/"))
04566             url.chop(1);
04567     }
04568 
04569     if (!(options & QUrl::RemoveQuery) && d->hasQuery) {
04570         url += QLatin1Char('?');
04571         url += fromPercentEncoding(d->query);
04572     }
04573     if (!(options & QUrl::RemoveFragment) && d->hasFragment) {
04574         url += QLatin1Char('#');
04575         url += d->fragment;
04576     }
04577 
04578     return url;
04579 }

Here is the call graph for this function:

QByteArray QUrl::toEncoded ( FormattingOptions  options = None  )  const

Returns the encoded representation of the URL if it's valid; otherwise an empty QByteArray is returned. The output can be customized by passing flags with options.

The user info, path and fragment are all converted to UTF-8, and all non-ASCII characters are then percent encoded. The host name is encoded using Punycode.

Definition at line 4590 of file qurl.cpp.

References d, and QUrlPrivate::toEncoded().

Referenced by QHttpPrivate::_q_slotSendRequest(), launch(), operator<<(), and QMimeDataPrivate::retrieveTypedData().

04591 {
04592     return d->toEncoded(options);
04593 }

Here is the call graph for this function:

QUrl QUrl::fromEncoded ( const QByteArray input  )  [static]

Parses input and returns the corresponding QUrl. input is assumed to be in encoded form, containing only ASCII characters.

The URL is parsed using TolerantMode.

See also:
toEncoded(), setUrl()

Definition at line 4603 of file qurl.cpp.

References setEncodedUrl(), and TolerantMode.

Referenced by QHttpPrivate::_q_slotSendRequest(), operator>>(), and QMimeDataPrivate::retrieveTypedData().

04604 {
04605     QUrl tmp;
04606     tmp.setEncodedUrl(input, TolerantMode);
04607     return tmp;
04608 }

Here is the call graph for this function:

QUrl QUrl::fromEncoded ( const QByteArray input,
ParsingMode  parsingMode 
) [static]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Parses the URL using parsingMode.

See also:
toEncoded(), setUrl()

Definition at line 4617 of file qurl.cpp.

References setEncodedUrl().

04618 {
04619     QUrl tmp;
04620     tmp.setEncodedUrl(input, parsingMode);
04621     return tmp;
04622 }

Here is the call graph for this function:

void QUrl::detach (  ) 

Definition at line 5105 of file qurl.cpp.

References d, and qAtomicDetach().

Referenced by addQueryItem(), clear(), removeAllQueryItems(), removeQueryItem(), setAuthority(), setEncodedQuery(), setFragment(), setHost(), setPassword(), setPath(), setPort(), setQueryDelimiters(), setQueryItems(), setScheme(), setUserInfo(), and setUserName().

05106 { qAtomicDetach(d); }

Here is the call graph for this function:

bool QUrl::isDetached (  )  const

Definition at line 5111 of file qurl.cpp.

References d, and QUrlPrivate::ref.

05112 {
05113     return d->ref == 1;
05114 }

bool QUrl::operator< ( const QUrl url  )  const

Definition at line 5055 of file qurl.cpp.

References d, QUrlPrivate::normalized(), QUrlPrivate::parse(), QUrlPrivate::Parsed, QURL_HASFLAG, and QUrlPrivate::stateFlags.

05056 {
05057     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
05058     if (!QURL_HASFLAG(url.d->stateFlags, QUrlPrivate::Parsed)) url.d->parse();
05059     return d->normalized() < url.d->normalized();
05060 }

Here is the call graph for this function:

bool QUrl::operator== ( const QUrl url  )  const

Returns true if this URL and the given url are equal; otherwise returns false.

Definition at line 5066 of file qurl.cpp.

References d, QUrlPrivate::normalized(), QUrlPrivate::parse(), QUrlPrivate::Parsed, QURL_HASFLAG, and QUrlPrivate::stateFlags.

05067 {
05068     if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
05069     if (!QURL_HASFLAG(url.d->stateFlags, QUrlPrivate::Parsed)) url.d->parse();
05070     return d->normalized() == url.d->normalized();
05071 }

Here is the call graph for this function:

bool QUrl::operator!= ( const QUrl url  )  const

Returns true if this URL and the given url are not equal; otherwise returns false.

Definition at line 5077 of file qurl.cpp.

05078 {
05079     return !(*this == url);
05080 }

QString QUrl::fromPercentEncoding ( const QByteArray input  )  [static]

Returns a decoded copy of input. input is first decoded from percent encoding, then converted from UTF-8 to unicode.

Definition at line 4628 of file qurl.cpp.

References a, b, QString::constData(), QByteArray::constData(), QByteArray::count(), data, QByteArray::data(), QString::fromUtf8(), i, len, qDebug(), and QByteArray::size().

Referenced by QUrlPrivate::parse(), queryItems(), and toString().

04629 {
04630     QVarLengthArray<char> tmp(input.size() + 1);
04631 
04632     char *data = tmp.data();
04633     const char *inputPtr = input.constData();
04634 
04635     int i = 0;
04636     int len = input.count();
04637     int a, b;
04638     char c;
04639     while (i < len) {
04640         c = inputPtr[i];
04641         if (c == '%' && i + 2 < len) {
04642             a = inputPtr[++i];
04643             b = inputPtr[++i];
04644 
04645             if (a >= '0' && a <= '9') a -= '0';
04646             else if (a >= 'a' && a <= 'f') a = a - 'a' + 10;
04647             else if (a >= 'A' && a <= 'F') a = a - 'A' + 10;
04648 
04649             if (b >= '0' && b <= '9') b -= '0';
04650             else if (b >= 'a' && b <= 'f') b  = b - 'a' + 10;
04651             else if (b >= 'A' && b <= 'F') b  = b - 'A' + 10;
04652 
04653             *data++ = (char)((a << 4) | b);
04654         } else {
04655             *data++ = c;
04656         }
04657 
04658         ++i;
04659     }
04660 
04661     *data = '\0';
04662 
04663 #if defined QURL_DEBUG
04664     qDebug("QUrl::fromPercentEncoding(\"%s\") == \"%s\"", input.data(), QString::fromUtf8(tmp.data()).toLatin1().constData());
04665 #endif
04666 
04667     return QString::fromUtf8(tmp.data());
04668 }

Here is the call graph for this function:

QByteArray QUrl::toPercentEncoding ( const QString input,
const QByteArray exclude = QByteArray(),
const QByteArray include = QByteArray() 
) [static]

Returns an encoded copy of input. input is first converted to UTF-8, and all ASCII-characters that are not in the unreserved group are percent encoded. To prevent characters from being percent encoded pass them to exclude. To force characters to be percent encoded pass them to include.

Unreserved is defined as: ALPHA / DIGIT / "-" / "." / "_" / "~"

         QByteArray ba = QUrl::toPercentEncoding("{a fishy string?}", "{}", "s");
         qDebug(ba.constData());
         // prints "{a fi%73hy %73tring%3F}"

Definition at line 4704 of file qurl.cpp.

References QByteArray::constData(), QByteArray::count(), data, i, include(), QByteArray::isEmpty(), len, length, q_strchr(), qDebug(), QByteArray::size(), toHex(), QString::toLatin1(), QString::toUtf8(), x41, and x61.

Referenced by addQueryItem(), setQueryItems(), setUrl(), and QUrlPrivate::toEncoded().

04705 {
04706 
04707     QByteArray tmp = input.toUtf8();
04708     QVarLengthArray<char> output(tmp.size() * 3);
04709 
04710     int len = tmp.count();
04711     char *data = output.data();
04712     const char *inputData = tmp.constData();
04713     int length = 0;
04714 
04715     const char * dontEncode = 0;
04716     if (!exclude.isEmpty()) dontEncode = exclude.constData();
04717 
04718 
04719     if (include.isEmpty()) {
04720         for (int i = 0; i < len; ++i) {
04721             unsigned char c = *inputData++;
04722             if (c >= 0x61 && c <= 0x7A // ALPHA
04723                 || c >= 0x41 && c <= 0x5A // ALPHA
04724                 || c >= 0x30 && c <= 0x39 // DIGIT
04725                 || c == 0x2D // -
04726                 || c == 0x2E // .
04727                 || c == 0x5F // _
04728                 || c == 0x7E // ~
04729                 || q_strchr(dontEncode, c)) {
04730                 data[length++] = c;
04731             } else {
04732                 data[length++] = '%';
04733                 data[length++] = toHex((c & 0xf0) >> 4);
04734                 data[length++] = toHex(c & 0xf);
04735             }
04736         }
04737     } else {
04738         const char * alsoEncode = include.constData();
04739         for (int i = 0; i < len; ++i) {
04740             unsigned char c = *inputData++;
04741             if ((c >= 0x61 && c <= 0x7A // ALPHA
04742                 || c >= 0x41 && c <= 0x5A // ALPHA
04743                 || c >= 0x30 && c <= 0x39 // DIGIT
04744                 || c == 0x2D // -
04745                 || c == 0x2E // .
04746                 || c == 0x5F // _
04747                 || c == 0x7E // ~
04748                 || q_strchr(dontEncode, c))
04749                 && !q_strchr(alsoEncode, c)) {
04750                 data[length++] = c;
04751             } else {
04752                 data[length++] = '%';
04753                 data[length++] = toHex((c & 0xf0) >> 4);
04754                 data[length++] = toHex(c & 0xf);
04755             }
04756         }
04757     }
04758 
04759 #if defined QURL_DEBUG
04760     qDebug("QUrl::toPercentEncoding(\"%s\") == \"%s\"", input.toLatin1().constData(), QByteArray(output.data(), length).data());
04761 #endif
04762 
04763     return QByteArray(output.data(), length);
04764 }

Here is the call graph for this function:

QString QUrl::fromPunycode ( const QByteArray pc  )  [static]

Returns the Punycode decoded representation of pc.

Punycode is a Unicode encoding used for internationalized domain names, as defined in RFC3492. If you want to convert a domain from its ASCII-compatible encoding to the Unicode representation, use fromAce().

Definition at line 4897 of file qurl.cpp.

References adapt(), QByteArray::at(), base, QByteArray::constData(), i, initial_bias, initial_n, QString::insert(), QByteArray::lastIndexOf(), QByteArray::left(), QString::length(), QByteArray::length(), QByteArray::mid(), n, Q_MAXINT, QByteArray::size(), QByteArray::startsWith(), t, tmax, tmin, and w.

Referenced by qt_from_ACE().

04898 {
04899     uint n = initial_n;
04900     uint i = 0;
04901     uint bias = initial_bias;
04902 
04903     // strip any ACE prefix
04904     QByteArray inputTrimmed = (pc.startsWith("xn--") ? pc.mid(4) : pc);
04905 
04906     // find the last delimiter character '-' in the input array. copy
04907     // all data before this delimiter directly to the output array.
04908     int delimiterPos = inputTrimmed.lastIndexOf(0x2d);
04909     QString output = QLatin1String(delimiterPos == -1 ? "" : inputTrimmed.left(delimiterPos).constData());
04910 
04911     // if a delimiter was found, skip to the position after it;
04912     // otherwise start at the front of the input string. everything
04913     // before the delimiter is assumed to be basic code points.
04914     uint cnt = delimiterPos ? delimiterPos + 1 : 0;
04915 
04916     // loop through the rest of the input string, inserting non-basic
04917     // characters into output as we go.
04918     while (cnt < (uint) inputTrimmed.size()) {
04919         uint oldi = i;
04920         uint w = 1;
04921 
04922         // find the next index for inserting a non-basic character.
04923         for (uint k = base; cnt < (uint) inputTrimmed.length(); k += base) {
04924             // grab a character from the punycode input and find its
04925             // delta digit (each digit code is part of the
04926             // variable-length integer delta)
04927             uint digit = inputTrimmed.at(cnt++);
04928             if (digit - 48 < 10) digit -= 22;
04929             else if (digit - 65 < 26) digit -= 65;
04930             else if (digit - 97 < 26) digit -= 97;
04931             else digit = base;
04932 
04933             // reject out of range digits
04934             if (digit >= base || digit > (Q_MAXINT - i) / w)
04935                 return QLatin1String("");
04936 
04937             i += (digit * w);
04938 
04939             // detect threshold to stop reading delta digits
04940             uint t;
04941             if (k <= bias) t = tmin;
04942             else if (k >= bias + tmax) t = tmax;
04943             else t = k - bias;
04944             if (digit < t) break;
04945 
04946             w *= (base - t);
04947         }
04948 
04949         // find new bias and calculate the next non-basic code
04950         // character.
04951         bias = adapt(i - oldi, output.length() + 1, oldi == 0);
04952         n += i / (output.length() + 1);
04953 
04954         // allow the deltas to wrap around
04955         i %= (output.length() + 1);
04956 
04957         // insert the character n at position i
04958         output.insert((uint) i, QChar((ushort) n));
04959         ++i;
04960     }
04961 
04962     return output;
04963 }

Here is the call graph for this function:

QByteArray QUrl::toPunycode ( const QString uc  )  [static]

Returns a uc in Punycode encoding.

Punycode is a Unicode encoding used for internationalized domain names, as defined in RFC3492. If you want to convert a domain name from Unicode to its ASCII-compatible representation, use toAce().

Definition at line 4791 of file qurl.cpp.

References adapt(), QString::at(), b, base, encodeDigit(), h, initial_bias, initial_n, j, QString::length(), m, n, QByteArray::prepend(), Q_MAXINT, QByteArray::size(), t, tmax, tmin, QChar::unicode(), and x80.

Referenced by toAce().

04792 {
04793     uint n = initial_n;
04794     uint delta = 0;
04795     uint bias = initial_bias;
04796 
04797     // assume that the size of output will be smaller than the number
04798     // of input characters.
04799     QByteArray output;
04800 
04801     int ucLength = uc.length();
04802 
04803     // copy all basic code points verbatim to output.
04804     for (uint j = 0; j < (uint) ucLength; ++j) {
04805         ushort js = uc.at(j).unicode();
04806         if (js < 0x80)
04807             output += js;
04808     }
04809 
04810     // if there were only basic code points, just return them
04811     // directly; don't do any encoding.
04812     if (output.size() == ucLength)
04813         return output;
04814 
04815     // h and b now contain the number of basic code points in input.
04816     uint b = output.size();
04817     uint h = output.size();
04818 
04819     // if basic code points were copied, add the delimiter character.
04820     if (h > 0) output += 0x2d;
04821 
04822     // while there are still unprocessed non-basic code points left in
04823     // the input string...
04824     while (h < (uint) ucLength) {
04825         // find the character in the input string with the lowest
04826         // unicode value.
04827         uint m = Q_MAXINT;
04828         uint j;
04829         for (j = 0; j < (uint) ucLength; ++j) {
04830             if (uc.at(j).unicode() >= n && uc.at(j).unicode() < m)
04831                 m = (uint) uc.at(j).unicode();
04832         }
04833 
04834         // reject out-of-bounds unicode characters
04835         if (m - n > (Q_MAXINT - delta) / (h + 1))
04836             return ""; // punycode_overflow
04837 
04838         delta += (m - n) * (h + 1);
04839         n = m;
04840 
04841         // for each code point in the input string
04842         for (j = 0; j < (uint) ucLength; ++j) {
04843 
04844             // increase delta until we reach the character with the
04845             // lowest unicode code. fail if delta overflows.
04846             if (uc.at(j).unicode() < n) {
04847                 ++delta;
04848                 if (!delta)
04849                     return ""; // punycode_overflow
04850             }
04851 
04852             // if j is the index of the character with the lowest
04853             // unicode code...
04854             if (uc.at(j).unicode() == n) {
04855                 uint qq;
04856                 uint k;
04857                 uint t;
04858 
04859                 // insert the variable length delta integer; fail on
04860                 // overflow.
04861                 for (qq = delta, k = base;; k += base) {
04862                     // stop generating digits when the threshold is
04863                     // detected.
04864                     t = (k <= bias) ? tmin : (k >= bias + tmax) ? tmax : k - bias;
04865                     if (qq < t) break;
04866 
04867                     output += encodeDigit(t + (qq - t) % (base - t));
04868                     qq = (qq - t) / (base - t);
04869                 }
04870 
04871                 output += encodeDigit(qq);
04872                 bias = adapt(delta, h + 1, h == b);
04873                 delta = 0;
04874                 ++h;
04875             }
04876         }
04877 
04878         ++delta;
04879         ++n;
04880     }
04881 
04882     // prepend ACE prefix
04883     output.prepend("xn--");
04884     return output;
04885 
04886 }

Here is the call graph for this function:

QString QUrl::fromAce ( const QByteArray domain  )  [static]

Since:
4.2
Returns the Unicode form of the given domain name domain, which is encoded in the ASCII Compatible Encoding (ACE). The result of this function is considered equivalent to domain.

If the value in domain cannot be encoded, it will be converted to QString and returned.

The ASCII Compatible Encoding (ACE) is defined by RFC 3490, RFC 3491 and RFC 3492. It is part of the Internationalizing Domain Names in Applications (IDNA) specification, which allows for domain names (like "www.trolltech.com") to be written using international characters.

Definition at line 4981 of file qurl.cpp.

References QString::fromLatin1(), and qt_from_ACE().

04982 {
04983     return qt_from_ACE(QString::fromLatin1(domain));
04984 }

Here is the call graph for this function:

QByteArray QUrl::toAce ( const QString domain  )  [static]

Since:
4.2
Returns the ASCII Compatible Encoding of the given domain name domain. The result of this function is considered equivalent to domain.

The ASCII-Compatible Encoding (ACE) is defined by RFC 3490, RFC 3491 and RFC 3492. It is part of the Internationalizing Domain Names in Applications (IDNA) specification, which allows for domain names (like "www.trolltech.com") to be written using international characters.

Definition at line 4998 of file qurl.cpp.

References QList< T >::at(), QList< T >::count(), QString::fromUtf16(), i, qt_nameprep(), QString::split(), and toPunycode().

Referenced by QHostInfo::fromName(), QHostInfo::lookupHost(), and QUrlPrivate::toEncoded().

04999 {
05000     // IDNA / rfc3490 describes these four delimiters used for
05001     // separating labels in unicode international domain
05002     // names.
05003     const unsigned short delimiters[] = {'[', 0x2e, 0x3002, 0xff0e, 0xff61, ']', 0};
05004     QStringList labels = domain.split(QRegExp(QString::fromUtf16(delimiters)));
05005     QByteArray result;
05006     for (int i = 0; i < labels.count(); ++i) {
05007         if (i != 0) result += '.';
05008         result += toPunycode(qt_nameprep(labels.at(i)));
05009     }
05010     return result;
05011 }

Here is the call graph for this function:

QStringList QUrl::idnWhitelist (  )  [static]

Since:
4.2
Returns the current whitelist of top-level domains that are allowed to have non-ASCII characters in their compositions.

See setIdnWhitelist() for the rationale of this list.

Definition at line 5021 of file qurl.cpp.

Referenced by setIdnWhitelist().

05022 {
05023     return *::idnWhitelist();
05024 }

void QUrl::setIdnWhitelist ( const QStringList list  )  [static]

Since:
4.2
Sets the whitelist of Top-Level Domains (TLDs) that are allowed to have non-ASCII characters in domains to the value of list.

Qt has comes a default list that contains the Internet top-level domains that have published support for Internationalized Domain Names (IDNs) and rules to guarantee that no deception can happen between similarly-looking characters (such as the Latin lowercase letter 'a' and the Cyrillic equivalent, which in most fonts are visually identical).

This list is periodically maintained, as registrars publish new rules.

This function is provided for those who need to manipulate the list, in order to add or remove a TLD. It is not recommended to change its value for purposes other than testing, as it may expose users to security risks.

Definition at line 5044 of file qurl.cpp.

References idnWhitelist().

05045 {
05046     static_cast<QStringList &>(*::idnWhitelist()) = list;
05047 }

Here is the call graph for this function:

QString QUrl::errorString (  )  const

Since:
4.2
Returns a text string that explains why an URL is invalid in the case being; otherwise returns an empty string.

Definition at line 5411 of file qurl.cpp.

References QUrlPrivate::createErrorString(), and d.

05412 {
05413     return d->createErrorString();
05414 }

Here is the call graph for this function:


Friends And Related Function Documentation

QDataStream & operator<< ( QDataStream out,
const QUrl url 
) [related]

Writes url url to the stream out and returns a reference to the stream.

See also:
Format of the QDataStream operators

Definition at line 5374 of file qurl.cpp.

References toEncoded(), and u.

Referenced by operator<<().

05375 {
05376     QByteArray u = url.toEncoded();
05377     out << u;
05378     return out;
05379 }

Here is the call graph for this function:

QDataStream & operator>> ( QDataStream in,
QUrl url 
) [related]

Reads a url into url from the stream in and returns a reference to the stream.

See also:
Format of the QDataStream operators

Definition at line 5388 of file qurl.cpp.

References fromEncoded(), and u.

Referenced by operator>>().

05389 {
05390     QByteArray u;
05391     in >> u;
05392     url = QUrl::fromEncoded(u);
05393     return in;
05394 }

Here is the call graph for this function:


Member Data Documentation

QUrlPrivate* QUrl::d [private]

Definition at line 219 of file qurl.h.

Referenced by addQueryItem(), allQueryItemValues(), authority(), clear(), detach(), encodedQuery(), errorString(), fragment(), hasFragment(), hasQuery(), hasQueryItem(), host(), isDetached(), isEmpty(), isParentOf(), isRelative(), isValid(), operator<(), operator=(), operator==(), password(), path(), port(), queryItems(), queryItemValue(), queryPairDelimiter(), queryValueDelimiter(), QUrl(), removeAllQueryItems(), removeQueryItem(), resolved(), scheme(), setAuthority(), setEncodedQuery(), setEncodedUrl(), setFragment(), setHost(), setPassword(), setPath(), setPort(), setQueryDelimiters(), setQueryItems(), setScheme(), setUserInfo(), setUserName(), toEncoded(), toLocalFile(), toString(), userInfo(), userName(), and ~QUrl().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 19:42:09 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1