Qt 4.8
|
The QUrl class provides a convenient interface for working with URLs. More...
#include <qurl.h>
Public Types | |
typedef QUrlPrivate * | DataPtr |
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 } |
The formatting options define how the URL is formatted when written out as text. More... | |
enum | ParsingMode { TolerantMode, StrictMode } |
The parsing mode controls the way QUrl parses strings. More... | |
Public Functions | |
void | addEncodedQueryItem (const QByteArray &key, const QByteArray &value) |
Inserts the pair key = value into the query string of the URL. More... | |
void | addQueryItem (const QString &key, const QString &value) |
Inserts the pair key = value into the query string of the URL. More... | |
QList< QByteArray > | allEncodedQueryItemValues (const QByteArray &key) const |
Returns the a list of query string values whose key is equal to key from the URL. More... | |
QStringList | allQueryItemValues (const QString &key) const |
Returns the a list of query string values whose key is equal to key from the URL. More... | |
QString | authority () const |
Returns the authority of the URL if it is defined; otherwise an empty string is returned. More... | |
void | clear () |
Resets the content of the QUrl. More... | |
DataPtr & | data_ptr () |
void | detach () |
Forces a detach. More... | |
QByteArray | encodedFragment () const |
Returns the fragment of the URL if it is defined; otherwise an empty string is returned. More... | |
QByteArray | encodedHost () const |
Returns the host part of the URL if it is defined; otherwise an empty string is returned. More... | |
QByteArray | encodedPassword () const |
Returns the password of the URL if it is defined; otherwise an empty string is returned. More... | |
QByteArray | encodedPath () const |
Returns the path of the URL if it is defined; otherwise an empty string is returned. More... | |
QByteArray | encodedQuery () const |
Returns the query string of the URL in percent encoded form. More... | |
QList< QPair< QByteArray, QByteArray > > | encodedQueryItems () const |
Returns the query string of the URL, as a map of encoded keys and values. More... | |
QByteArray | encodedQueryItemValue (const QByteArray &key) const |
Returns the first query string value whose key is equal to key from the URL. More... | |
QByteArray | encodedUserName () const |
Returns the user name of the URL if it is defined; otherwise an empty string is returned. More... | |
QString | errorString () const |
Returns a text string that explains why an URL is invalid in the case being; otherwise returns an empty string. More... | |
QString | fragment () const |
Returns the fragment of the URL. More... | |
bool | hasEncodedQueryItem (const QByteArray &key) const |
Returns true if there is a query string pair whose key is equal to key from the URL. More... | |
bool | hasFragment () const |
Returns true if this URL contains a fragment (i. More... | |
bool | hasQuery () const |
Returns true if this URL contains a Query (i. More... | |
bool | hasQueryItem (const QString &key) const |
Returns true if there is a query string pair whose key is equal to key from the URL. More... | |
QString | host () const |
Returns the host of the URL if it is defined; otherwise an empty string is returned. More... | |
bool | isDetached () const |
bool | isEmpty () const |
Returns true if the URL has no data; otherwise returns false. More... | |
bool | isLocalFile () const |
Returns true if this URL is pointing to a local file path. More... | |
bool | isParentOf (const QUrl &url) const |
Returns true if this URL is a parent of childUrl. More... | |
bool | isRelative () const |
Returns true if the URL is relative; otherwise returns false. More... | |
bool | isValid () const |
Returns true if the URL is valid; otherwise returns false. More... | |
bool | operator!= (const QUrl &url) const |
Returns true if this URL and the given url are not equal; otherwise returns false. More... | |
bool | operator< (const QUrl &url) const |
Returns true if this URL is "less than" the given url. More... | |
QUrl & | operator= (const QUrl ©) |
Assigns the specified url to this object. More... | |
QUrl & | operator= (const QString &url) |
Assigns the specified url to this object. More... | |
bool | operator== (const QUrl &url) const |
Returns true if this URL and the given url are equal; otherwise returns false. More... | |
QString | password () const |
Returns the password of the URL if it is defined; otherwise an empty string is returned. More... | |
QString | path () const |
Returns the path of the URL. More... | |
int | port () const |
Returns the port of the URL, or -1 if the port is unspecified. More... | |
int | port (int defaultPort) const |
Returns the port of the URL, or defaultPort if the port is unspecified. More... | |
QList< QPair< QString, QString > > | queryItems () const |
Returns the query string of the URL, as a map of keys and values. More... | |
QString | queryItemValue (const QString &key) const |
Returns the first query string value whose key is equal to key from the URL. More... | |
char | queryPairDelimiter () const |
Returns the character used to delimit between key-value pairs in the query string of the URL. More... | |
char | queryValueDelimiter () const |
Returns the character used to delimit between keys and values in the query string of the URL. More... | |
QUrl () | |
Constructs an empty QUrl object. More... | |
QUrl (const QString &url) | |
Constructs a URL by parsing url. More... | |
QUrl (const QString &url, ParsingMode mode) | |
Parses the url using the parser mode parsingMode. More... | |
QUrl (const QUrl ©) | |
Constructs a copy of other. More... | |
void | removeAllEncodedQueryItems (const QByteArray &key) |
Removes all the query string pairs whose key is equal to key from the URL. More... | |
void | removeAllQueryItems (const QString &key) |
Removes all the query string pairs whose key is equal to key from the URL. More... | |
void | removeEncodedQueryItem (const QByteArray &key) |
Removes the first query string pair whose key is equal to key from the URL. More... | |
void | removeQueryItem (const QString &key) |
Removes the first query string pair whose key is equal to key from the URL. More... | |
QUrl | resolved (const QUrl &relative) const |
Returns the result of the merge of this URL with relative. More... | |
QString | scheme () const |
Returns the scheme of the URL. More... | |
void | setAuthority (const QString &authority) |
Sets the authority of the URL to authority. More... | |
void | setEncodedFragment (const QByteArray &fragment) |
Sets the URL's fragment to the percent-encoded fragment. More... | |
void | setEncodedHost (const QByteArray &host) |
Sets the URL's host to the ACE- or percent-encoded host. More... | |
void | setEncodedPassword (const QByteArray &password) |
Sets the URL's password to the percent-encoded password. More... | |
void | setEncodedPath (const QByteArray &path) |
Sets the URL's path to the percent-encoded path. More... | |
void | setEncodedQuery (const QByteArray &query) |
Sets the query string of the URL to query. More... | |
void | setEncodedQueryItems (const QList< QPair< QByteArray, QByteArray > > &query) |
Sets the query string of the URL to the encoded version of query. More... | |
void | setEncodedUrl (const QByteArray &url) |
Constructs a URL by parsing the contents of encodedUrl. More... | |
void | setEncodedUrl (const QByteArray &url, ParsingMode mode) |
Constructs a URL by parsing the contents of encodedUrl using the given parsingMode. More... | |
void | setEncodedUserName (const QByteArray &userName) |
Sets the URL's user name to the percent-encoded userName. More... | |
void | setFragment (const QString &fragment) |
Sets the fragment of the URL to fragment. More... | |
void | setHost (const QString &host) |
Sets the host of the URL to host. More... | |
void | setPassword (const QString &password) |
Sets the URL's password to password. More... | |
void | setPath (const QString &path) |
Sets the path of the URL to path. More... | |
void | setPort (int port) |
Sets the port of the URL to port. More... | |
void | 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. More... | |
void | setQueryItems (const QList< QPair< QString, QString > > &query) |
Sets the query string of the URL to an encoded version of query. More... | |
void | setScheme (const QString &scheme) |
Sets the scheme of the URL to scheme. More... | |
void | setUrl (const QString &url) |
Constructs a URL by parsing the contents of url. More... | |
void | setUrl (const QString &url, ParsingMode mode) |
Parses url using the parsing mode parsingMode. More... | |
void | setUserInfo (const QString &userInfo) |
Sets the user info of the URL to userInfo. More... | |
void | setUserName (const QString &userName) |
Sets the URL's user name to userName. More... | |
void | swap (QUrl &other) |
Swaps URL other with this URL. More... | |
QByteArray | toEncoded (FormattingOptions options=None) const |
Returns the encoded representation of the URL if it's valid; otherwise an empty QByteArray is returned. More... | |
QString | toLocalFile () const |
Returns the path of this URL formatted as a local file path. More... | |
QString | topLevelDomain () const |
Returns the TLD (Top-Level Domain) of the URL, (e. More... | |
QString | toString (FormattingOptions options=None) const |
Returns the human-displayable string representation of the URL. More... | |
QString | userInfo () const |
Returns the user info of the URL, or an empty string if the user info is undefined. More... | |
QString | userName () const |
Returns the user name of the URL if it is defined; otherwise an empty string is returned. More... | |
~QUrl () | |
Destructor; called immediately before the object is deleted. More... | |
Static Public Functions | |
static QString | fromAce (const QByteArray &) |
Returns the Unicode form of the given domain name domain, which is encoded in the ASCII Compatible Encoding (ACE). More... | |
static QUrl | fromEncoded (const QByteArray &url) |
Parses input and returns the corresponding QUrl. More... | |
static QUrl | fromEncoded (const QByteArray &url, ParsingMode mode) |
Parses the URL using parsingMode. More... | |
static QUrl | fromLocalFile (const QString &localfile) |
Returns a QUrl representation of localFile, interpreted as a local file. More... | |
static QString | fromPercentEncoding (const QByteArray &) |
Returns a decoded copy of input. More... | |
static QString | fromPunycode (const QByteArray &) |
Returns the Punycode decoded representation of pc. More... | |
static QUrl | fromUserInput (const QString &userInput) |
Returns a valid URL from a user supplied userInput string if one can be deducted. More... | |
static QStringList | idnWhitelist () |
Returns the current whitelist of top-level domains that are allowed to have non-ASCII characters in their compositions. More... | |
static void | setIdnWhitelist (const QStringList &) |
Sets the whitelist of Top-Level Domains (TLDs) that are allowed to have non-ASCII characters in domains to the value of list. More... | |
static QByteArray | toAce (const QString &) |
Returns the ASCII Compatible Encoding of the given domain name domain. More... | |
static QByteArray | toPercentEncoding (const QString &, const QByteArray &exclude=QByteArray(), const QByteArray &include=QByteArray()) |
Returns an encoded copy of input. More... | |
static QByteArray | toPunycode (const QString &) |
Returns a uc in Punycode encoding. More... | |
Private Functions | |
void | detach (QMutexLocker &locker) |
Forces a detach. More... | |
Properties | |
QUrlPrivate * | d |
Related Functions | |
(Note that these are not member functions.) | |
QDataStream & | operator<< (QDataStream &out, const QUrl &url) |
Writes url url to the stream out and returns a reference to the stream. More... | |
QDataStream & | operator>> (QDataStream &in, QUrl &url) |
Reads a url into url from the stream in and returns a reference to the stream. More... | |
uint | qHash (const QUrl &url) |
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/List of applicants.xml" would be sent to the server as "http://xn--bhler-kva.example.com/List%20of%20applicants.xml", and this can be verified by calling the toEncoded() function.
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)).
Follow these rules to avoid erroneous character conversion when dealing with URLs and strings:
The formatting options define how the URL is formatted when written out as text.
Note that the case folding rules in RFC 3491{Nameprep}, which QUrl conforms to, require host names to always be converted to lower case, regardless of the Qt::FormattingOptions used.
Enumerator | |
---|---|
None | |
RemoveScheme | |
RemovePassword | |
RemoveUserInfo | |
RemovePort | |
RemoveAuthority | |
RemovePath | |
RemoveQuery | |
RemoveFragment | |
StripTrailingSlash |
enum QUrl::ParsingMode |
The parsing mode controls the way QUrl parses strings.
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".
Reserved and unreserved characters: An encoded URL should only contain a few characters as literals; all other characters should be percent-encoded. In TolerantMode, these characters will be automatically percent-encoded where they are not allowed: space / double-quote / "<" / ">" / "[" / "\" / "]" / "^" / "`" / "{" / "|" / "}"
Enumerator | |
---|---|
TolerantMode | |
StrictMode |
QUrl::QUrl | ( | ) |
Constructs an empty QUrl object.
Definition at line 4272 of file qurl.cpp.
Referenced by fromUserInput().
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. The default parsing mode is TolerantMode.
Example:
To construct a URL from an encoded string, call fromEncoded():
Definition at line 4242 of file qurl.cpp.
QUrl::QUrl | ( | const QString & | url, |
ParsingMode | parsingMode | ||
) |
Parses the url using the parser mode parsingMode.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
The default parsing mode is TolerantMode.
Definition at line 4259 of file qurl.cpp.
QUrl::QUrl | ( | const QUrl & | copy | ) |
QUrl::~QUrl | ( | ) |
void QUrl::addEncodedQueryItem | ( | const QByteArray & | key, |
const QByteArray & | value | ||
) |
Inserts the pair key = value into the query string of the URL.
Note: this function does not verify that either key or value are properly encoded. It is the caller's responsibility to ensure that the query delimiters are properly encoded, if any.
Definition at line 5279 of file qurl.cpp.
Inserts the pair key = value into the query string of the URL.
The key/value pair is encoded before it is added to the query. The pair is converted into separate strings internally. The key and value is first encoded into UTF-8 and then delimited by the character returned by valueDelimiter(). Each key/value pair is delimited by the character returned by pairDelimiter().
Definition at line 5240 of file qurl.cpp.
QList< QByteArray > QUrl::allEncodedQueryItemValues | ( | const QByteArray & | key | ) | const |
Returns the a list of query string values whose key is equal to key from the URL.
Note: if the encoded key does not match the encoded version of the query, this function will not work. That is, if the encoded query of this URL is "search=Qt%20Rules", calling this function with key = "%73earch" will return an empty list.
Definition at line 5516 of file qurl.cpp.
QStringList QUrl::allQueryItemValues | ( | const QString & | key | ) | const |
Returns the a list of query string values whose key is equal to key from the URL.
Definition at line 5474 of file qurl.cpp.
QString QUrl::authority | ( | ) | const |
Returns the authority of the URL if it is defined; otherwise an empty string is returned.
Definition at line 4592 of file qurl.cpp.
Referenced by QNetworkAccessFileBackendFactory::create(), isParentOf(), and QDeclarativeEnginePrivate::urlToLocalFileOrQrc().
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 4340 of file qurl.cpp.
Referenced by operator=().
|
inline |
void QUrl::detach | ( | ) |
Forces a detach.
Definition at line 6313 of file qurl.cpp.
Referenced by addEncodedQueryItem(), addQueryItem(), removeAllEncodedQueryItems(), removeEncodedQueryItem(), setAuthority(), setEncodedFragment(), setEncodedPassword(), setEncodedPath(), setEncodedQuery(), setEncodedQueryItems(), setEncodedUrl(), setEncodedUserName(), setFragment(), setHost(), setPassword(), setPath(), setPort(), setQueryDelimiters(), setQueryItems(), setScheme(), setUrl(), setUserInfo(), and setUserName().
|
private |
Forces a detach.
Unlocks locker once the detaching is done.
It's ok to access private members afterwards, without lock, since after detaching we have our private copy of the d pointer, that no other QUrl instance can know about yet.
Definition at line 6336 of file qurl.cpp.
QByteArray QUrl::encodedFragment | ( | ) | const |
Returns the fragment of the URL if it is defined; otherwise an empty string is returned.
The returned value will have its non-ASCII and other control characters percent-encoded, as in toEncoded().
Definition at line 5753 of file qurl.cpp.
Referenced by QUrlPrivate::fragmentImpl().
QByteArray QUrl::encodedHost | ( | ) | const |
Returns the host part of the URL if it is defined; otherwise an empty string is returned.
Note: encodedHost() does not return percent-encoded hostnames. Instead, the ACE-encoded (bare ASCII in Punycode encoding) form will be returned for any non-ASCII hostname.
This function is equivalent to calling QUrl::toAce() on the return value of host().
Definition at line 4884 of file qurl.cpp.
QByteArray QUrl::encodedPassword | ( | ) | const |
Returns the password of the URL if it is defined; otherwise an empty string is returned.
The returned value will have its non-ASCII and other control characters percent-encoded, as in toEncoded().
Definition at line 4805 of file qurl.cpp.
QByteArray QUrl::encodedPath | ( | ) | const |
Returns the path of the URL if it is defined; otherwise an empty string is returned.
The returned value will have its non-ASCII and other control characters percent-encoded, as in toEncoded().
Definition at line 5038 of file qurl.cpp.
QByteArray QUrl::encodedQuery | ( | ) | const |
Returns the query string of the URL in percent encoded form.
Definition at line 5643 of file qurl.cpp.
Referenced by QHttpNetworkRequestPrivate::header().
QList< QPair< QByteArray, QByteArray > > QUrl::encodedQueryItems | ( | ) | const |
Returns the query string of the URL, as a map of encoded keys and values.
Definition at line 5342 of file qurl.cpp.
QByteArray QUrl::encodedQueryItemValue | ( | const QByteArray & | key | ) | const |
Returns the first query string value whose key is equal to key from the URL.
Note: if the encoded key does not match the encoded version of the query, this function will not work. That is, if the encoded query of this URL is "search=Qt%20Rules", calling this function with key = "%73earch" will return an empty string.
Definition at line 5445 of file qurl.cpp.
Referenced by queryItemValue().
QByteArray QUrl::encodedUserName | ( | ) | const |
Returns the user name of the URL if it is defined; otherwise an empty string is returned.
The returned value will have its non-ASCII and other control characters percent-encoded, as in toEncoded().
Definition at line 4719 of file qurl.cpp.
QString QUrl::errorString | ( | ) | const |
Returns a text string that explains why an URL is invalid in the case being; otherwise returns an empty string.
Definition at line 6800 of file qurl.cpp.
QString QUrl::fragment | ( | ) | const |
Returns the fragment of the URL.
Definition at line 5687 of file qurl.cpp.
Referenced by QPatternist::ReportContext::codeFromURI(), QUrlPrivate::fragmentImpl(), QPatternist::ColoringMessageHandler::handleMessage(), setEncodedFragment(), setFragment(), and QTextBrowserPrivate::setSource().
|
static |
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 "example.com"
) to be written using international characters.
Definition at line 6134 of file qurl.cpp.
Referenced by interfaceListing(), QHostInfo::localDomainName(), and QNetworkCookiePrivate::parseSetCookieHeaderLine().
|
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.
Definition at line 5964 of file qurl.cpp.
Referenced by QHttpPrivate::_q_slotSendRequest(), QNetworkAccessHttpBackend::checkForRedirect(), QMacPasteboardMimeFileUri::convertToMime(), QMacPasteboardMimeUrl::convertToMime(), fromUserInput(), getImage(), getPixmap(), operator>>(), parseHeaderValue(), qmlxmlhttprequest_open(), QTextBrowserPrivate::resolveUrl(), QMimeDataPrivate::retrieveTypedData(), and QTextOdfWriter::writeInlineCharacter().
|
static |
Parses the URL using parsingMode.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 5981 of file qurl.cpp.
Returns a QUrl representation of localFile, interpreted as a local file.
This function accepts paths separated by slashes as well as the native separator for this platform.
This function also accepts paths with a doubled leading slash (or backslash) to indicate a remote file, as in "//servername/path/to/file.txt". Note that only certain platforms can actually open this file using QFile::open().
Definition at line 6374 of file qurl.cpp.
Referenced by QFileDialogPrivate::_q_pathChanged(), QDeclarativeImportsPrivate::add(), QUrlModel::addUrls(), QDeclarativeEngine::baseUrl(), QWindowsMimeURI::convertToMime(), QmlJSDebugger::AbstractViewInspector::createQmlObject(), QFileDialogPrivate::createWidgets(), QDeclarativeFolderListModel::data(), fromUserInput(), QGtkStylePrivate::getFilesystemIcon(), QTextDocument::loadResource(), QDirModel::mimeData(), QFileSystemModel::mimeData(), QPatternist::XPathHelper::normalizeQueryURI(), QDeclarativeComponent::QDeclarativeComponent(), QFileOpenEvent::QFileOpenEvent(), QDeclarativeTypeLoader::qmlDirParser(), registerComponent(), resolveScheme(), QTextBrowserPrivate::resolveUrl(), QDeclarativeFolderListModel::setFolder(), QFileDialogComboBox::setHistory(), QmlApplicationViewer::setMainQmlFile(), and QFileDialogComboBox::showPopup().
|
static |
Returns a decoded copy of input.
input is first decoded from percent encoding, then converted from UTF-8 to unicode.
Definition at line 5992 of file qurl.cpp.
Referenced by QNetworkCookiePrivate::parseSetCookieHeaderLine(), swap(), and toString().
|
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 6044 of file qurl.cpp.
Referenced by qt_ACE_do().
Returns a valid URL from a user supplied userInput string if one can be deducted.
In the case that is not possible, an invalid QUrl() is returned.
Most applications that can browse the web, allow the user to input a URL in the form of a plain string. This string can be manually typed into a location bar, obtained from the clipboard, or passed in via command line arguments.
When the string is not already a valid URL, a best guess is performed, making various web related assumptions.
In the case the string corresponds to a valid file path on the system, a file:// URL is constructed, using QUrl::fromLocalFile().
If that is not the case, an attempt is made to turn the string into a http:// or ftp:// URL. The latter in the case the string starts with 'ftp'. The result is then passed through QUrl's tolerant parser, and in the case or success, a valid QUrl is returned, or else a QUrl().
Definition at line 6878 of file qurl.cpp.
bool QUrl::hasEncodedQueryItem | ( | const QByteArray & | key | ) | const |
Returns true if there is a query string pair whose key is equal to key from the URL.
Note: if the encoded key does not match the encoded version of the query, this function will return false. That is, if the encoded query of this URL is "search=Qt%20Rules", calling this function with key = "%73earch" will return false.
Definition at line 5394 of file qurl.cpp.
Referenced by hasQueryItem().
bool QUrl::hasFragment | ( | ) | const |
Returns true if this URL contains a fragment (i.
e., if # was seen on it).
\sa fragment(), setFragment()
Definition at line 5773 of file qurl.cpp.
Referenced by QTextDocument::loadResource(), and QTextBrowserPrivate::resolveUrl().
bool QUrl::hasQuery | ( | ) | const |
Returns true if this URL contains a Query (i.
e., if ? was seen on it).
\sa hasQueryItem(), encodedQuery()
Definition at line 5058 of file qurl.cpp.
Referenced by QHttpNetworkRequestPrivate::header().
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 5372 of file qurl.cpp.
QString QUrl::host | ( | ) | const |
Returns the host of the URL if it is defined; otherwise an empty string is returned.
Definition at line 4837 of file qurl.cpp.
Referenced by QMacPasteboardMimeFileUri::convertFromMime(), QMacPasteboardMimeUrl::convertFromMime(), QMacPasteboardMimeFileUri::convertToMime(), QMacPasteboardMimeUrl::convertToMime(), QNetworkCookieJar::cookiesForUrl(), encodedHost(), QDeclarativeEnginePrivate::getImageFromProvider(), QDeclarativeEnginePrivate::getImageProviderType(), QDeclarativeEnginePrivate::getPixmapFromProvider(), QNetworkAccessFileBackend::open(), QNetworkAccessFtpBackend::open(), QNetworkProxyQuery::peerHostName(), QGlobalNetworkProxy::proxyForQuery(), qDecodeDataUrl(), QNetworkReplyFileImpl::QNetworkReplyFileImpl(), QNetworkCookieJar::setCookiesFromUrl(), setHost(), QNetworkAccessBackend::start(), QHttpThreadDelegate::startRequest(), and topLevelDomain().
|
static |
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 6175 of file qurl.cpp.
bool QUrl::isDetached | ( | ) | const |
bool QUrl::isEmpty | ( | ) | const |
Returns true if the URL has no data; otherwise returns false.
Definition at line 4317 of file qurl.cpp.
Referenced by QNetworkAccessManagerPrivate::authenticationRequired(), QDeclarativeContext::baseUrl(), QDeclarativeConnections::connectSignals(), QNetworkAccessFileBackendFactory::create(), QDeclarativeBinding::createBinding(), QHttpNetworkConnectionChannel::ensureConnection(), QDeclarativeInclude::include(), QDeclarativeDataLoader::load(), QTextDocument::loadResource(), QDeclarativeComponent::loadUrl(), QPatternist::XPathHelper::normalizeQueryURI(), operator==(), QPatternist::AccelTree::printStats(), QDeclarativeContextData::resolvedUrl(), QDeclarativeImports::resolveType(), QXmlQuery::setFocus(), QXmlQuery::setQuery(), QDeclarativeImageBase::setSource(), QDeclarativeBorderImage::setSource(), QDeclarativeParticles::setSource(), toLocalFile(), toUrl(), QDeclarativeBinding::update(), QDeclarativePropertyPrivate::write(), QPatternist::XQueryTokenizer::XQueryTokenizer(), and QDeclarativeInfo::~QDeclarativeInfo().
bool QUrl::isLocalFile | ( | ) | const |
Returns true if this URL is pointing to a local file path.
Note that this function considers URLs with hostnames to be local file paths, even if the eventual file path cannot be opened with QFile::open().
Definition at line 6453 of file qurl.cpp.
Referenced by QNetworkAccessFileBackendFactory::create(), QNetworkAccessManager::createRequest(), and toLocalFile().
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 6469 of file qurl.cpp.
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 5880 of file qurl.cpp.
Referenced by QTextBrowserPrivate::_q_activateAnchor(), QDeclarativeImportDatabase::addImportPath(), QDeclarativeImportDatabase::addPluginPath(), QPatternist::ResourceLoader::announceCollection(), QPatternist::AccelTreeResourceLoader::announceDocument(), QPatternist::ResourceLoader::announceDocument(), QPatternist::ResourceLoader::announceUnparsedText(), QPatternist::GenericStaticContext::baseURI(), QDeclarativeEnginePrivate::createQmlObject(), QPatternist::DocAvailableFN::evaluateEBV(), QPatternist::DocFN::evaluateSingleton(), QPatternist::GenericStaticContext::GenericStaticContext(), QDeclarativeTypeLoader::get(), QDeclarativeTypeLoader::getQmldir(), QDeclarativeTypeLoader::getScript(), QDeclarativeInclude::include(), QPatternist::ResourceLoader::isDocumentAvailable(), QPatternist::ResourceLoader::isUnparsedTextAvailable(), QTextDocument::loadResource(), QDeclarativeComponent::loadUrl(), navigatorInvoke(), QPatternist::XPathHelper::normalizeQueryURI(), QPatternist::ResourceLoader::openCollection(), QPatternist::ResourceLoader::openDocument(), QPatternist::ResourceLoader::openUnparsedText(), QPatternist::XsdSchemaParser::parseImport(), QPatternist::XsdSchemaParser::parseInclude(), QPatternist::XsdSchemaParser::parseRedefine(), QDeclarativeWorkerScriptEnginePrivate::processLoad(), qmlxmlhttprequest_open(), registerComponent(), QPatternist::resolveAndCheckCollation(), QDeclarativeContextData::resolvedUrl(), QPatternist::ReportContext::resolveURI(), QTextBrowserPrivate::resolveUrl(), QPatternist::GenericStaticContext::setBaseURI(), QDeclarativeParticles::setSource(), QPatternist::StaticBaseURIContext::StaticBaseURIContext(), swap(), toUrl(), QPatternist::XsdValidatingInstanceReader::validate(), QDeclarativePropertyPrivate::write(), and QPatternist::yyparse().
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.
Definition at line 4303 of file qurl.cpp.
Referenced by QUrlModel::addUrls(), QPatternist::ResourceLoader::announceCollection(), QPatternist::AccelTreeResourceLoader::announceDocument(), QPatternist::ResourceLoader::announceDocument(), QPatternist::ResourceLoader::announceUnparsedText(), QNetworkDiskCachePrivate::cacheFileName(), QNetworkAccessHttpBackend::checkForRedirect(), QDeclarativeFolderListModel::componentComplete(), QPatternist::ExpressionFactory::createExpression(), QDeclarativeEnginePrivate::createQmlObject(), QNetworkDiskCache::data(), QDeclarativeWorkerScript::engine(), QPatternist::DocFN::evaluateSingleton(), fromUserInput(), QPatternist::ResourceLoader::isDocumentAvailable(), QSourceLocation::isNull(), QPatternist::ResourceLoader::isUnparsedTextAvailable(), launchWebBrowser(), QPatternist::AccelTreeResourceLoader::load(), lsOpen(), navigatorInvoke(), QPatternist::XPathHelper::normalizeQueryURI(), QPatternist::ResourceLoader::openCollection(), openDocument(), QPatternist::ResourceLoader::openDocument(), QPatternist::ResourceLoader::openUnparsedText(), parseHeaderValue(), QPatternist::XsdSchemaParser::parseImport(), QPatternist::XsdSchemaParser::parseInclude(), QPatternist::XsdSchemaParser::parseRedefine(), QNetworkDiskCache::prepare(), QDeclarativeContextData::resolvedUrl(), QPatternist::AccelTreeResourceLoader::retrieveDocument(), QXmlQuery::setFocus(), QFileDialogComboBox::setHistory(), QXmlQuery::setQuery(), QTextBrowser::setSource(), QTextBrowserPrivate::setSource(), QFileDialogComboBox::showPopup(), QPatternist::StaticBaseURIContext::StaticBaseURIContext(), QNetworkProxyFactory::systemProxyForQuery(), QPatternist::Tokenizer::Tokenizer(), QPatternist::XsdValidatingInstanceReader::validate(), and QPatternist::XQueryTokenizer::XQueryTokenizer().
bool QUrl::operator!= | ( | const QUrl & | url | ) | const |
bool QUrl::operator< | ( | const QUrl & | url | ) | const |
Returns true if this URL is "less than" the given url.
This provides a means of ordering URLs.
Definition at line 6228 of file qurl.cpp.
Assigns the specified url to this object.
Definition at line 6264 of file qurl.cpp.
Assigns the specified url to this object.
Definition at line 6283 of file qurl.cpp.
bool QUrl::operator== | ( | const QUrl & | url | ) | const |
Returns true if this URL and the given url are equal; otherwise returns false.
Definition at line 6242 of file qurl.cpp.
QString QUrl::password | ( | ) | const |
Returns the password of the URL if it is defined; otherwise an empty string is returned.
Definition at line 4754 of file qurl.cpp.
Referenced by QNetworkAccessManagerPrivate::authenticationRequired(), QNetworkAccessAuthenticationManager::fetchCachedCredentials(), QNetworkAccessFtpBackend::open(), QHttpNetworkConnectionChannel::sendRequest(), setEncodedPassword(), and setPassword().
QString QUrl::path | ( | ) | const |
Returns the path of the URL.
Definition at line 4977 of file qurl.cpp.
Referenced by QTextBrowserPrivate::_q_documentModified(), QDeclarativeCompiler::buildDynamicMeta(), QMacPasteboardMimeFileUri::convertFromMime(), QMacPasteboardMimeUrl::convertFromMime(), QMacPasteboardMimeFileUri::convertToMime(), QMacPasteboardMimeUrl::convertToMime(), QNetworkCookieJar::cookiesForUrl(), QDragManager::drag(), QNetworkAccessAuthenticationManager::fetchCachedCredentials(), QTextBrowserPrivate::findFile(), QNetworkAccessFtpBackend::ftpDone(), isParentOf(), QTextDocument::loadResource(), QNetworkAccessFileBackend::open(), QNetworkAccessFtpBackend::open(), QNetworkReplyFileImpl::QNetworkReplyFileImpl(), QUrlInfo::QUrlInfo(), readImage(), QSidebar::removeEntry(), QTextBrowserPrivate::resolveUrl(), QNetworkCookieJar::setCookiesFromUrl(), setEncodedPath(), QDeclarativeFolderListModel::setFolder(), setPath(), QUrlModel::setUrl(), toLocalFile(), toString(), QHttpNetworkRequestPrivate::uri(), and QDeclarativeEnginePrivate::urlToLocalFileOrQrc().
int QUrl::port | ( | ) | const |
Returns the port of the URL, or -1 if the port is unspecified.
Definition at line 4916 of file qurl.cpp.
Referenced by makeCacheKey(), QNetworkAccessFtpBackend::open(), QNetworkProxyQuery::peerPort(), QHttpNetworkConnectionPrivate::prepareRequest(), setPort(), and QHttpThreadDelegate::startRequest().
int QUrl::port | ( | int | defaultPort | ) | const |
Returns the port of the URL, or defaultPort if the port is unspecified.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Example:
Definition at line 4939 of file qurl.cpp.
Returns the query string of the URL, as a map of keys and values.
Definition at line 5305 of file qurl.cpp.
Returns the first query string value whose key is equal to key from the URL.
Definition at line 5422 of file qurl.cpp.
char QUrl::queryPairDelimiter | ( | ) | const |
char QUrl::queryValueDelimiter | ( | ) | const |
void QUrl::removeAllEncodedQueryItems | ( | const QByteArray & | key | ) |
Removes all the query string pairs whose key is equal to key from the URL.
Note: if the encoded key does not match the encoded version of the query, this function will not work. That is, if the encoded query of this URL is "search=Qt%20Rules", calling this function with key = "%73earch" will do nothing.
Definition at line 5617 of file qurl.cpp.
Referenced by removeAllQueryItems().
void QUrl::removeAllQueryItems | ( | const QString & | key | ) |
Removes all the query string pairs whose key is equal to key from the URL.
Definition at line 5595 of file qurl.cpp.
void QUrl::removeEncodedQueryItem | ( | const QByteArray & | key | ) |
Removes the first query string pair whose key is equal to key from the URL.
Note: if the encoded key does not match the encoded version of the query, this function will not work. That is, if the encoded query of this URL is "search=Qt%20Rules", calling this function with key = "%73earch" will do nothing.
Definition at line 5567 of file qurl.cpp.
Referenced by removeQueryItem().
void QUrl::removeQueryItem | ( | const QString & | key | ) |
Removes the first query string pair whose key is equal to key from the URL.
Definition at line 5545 of file qurl.cpp.
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:
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 "/".
Definition at line 5819 of file qurl.cpp.
Referenced by QHttpPrivate::_q_slotSendRequest(), QDeclarativeImportsPrivate::add(), QPatternist::AccelTree::baseUri(), QDeclarativeTypeData::dataReceived(), QDeclarativeImportsPrivate::find(), QDeclarativeImportedNamespace::find_helper(), QDeclarativeInclude::finished(), QDeclarativeXMLHttpRequest::finished(), QDeclarativeCompiler::genLiteralAssignment(), QDeclarativeInclude::include(), QTextDocument::loadResource(), QDeclarativeDataLoader::networkReplyFinished(), QDeclarativePixmapReader::networkRequestDone(), QPatternist::XsdSchemaParser::parseImport(), QPatternist::XsdSchemaParser::parseInclude(), QPatternist::XsdSchemaParser::parseRedefine(), QDeclarativeFontObject::replyFinished(), QDeclarativeScriptEngine::resolvedUrl(), QDeclarativeContextData::resolvedUrl(), QDeclarativeTypeData::resolveTypes(), QPatternist::AnyURI::resolveURI(), QPatternist::ReportContext::resolveURI(), QTextBrowserPrivate::resolveUrl(), QTextBrowserPrivate::setSource(), toUrl(), QPatternist::StaticBaseURIStore::typeCheck(), QPatternist::XsdValidatingInstanceReader::validate(), QDeclarativeInclude::worker_include(), and QPatternist::yyparse().
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.
Definition at line 4550 of file qurl.cpp.
Referenced by QTextBrowserPrivate::_q_activateAnchor(), QNetworkReplyImplPrivate::_q_startOperation(), QDeclarativeImportDatabase::addImportPath(), QDeclarativeImportDatabase::addPluginPath(), QUrlModel::addUrls(), QMacPasteboardMimeFileUri::convertFromMime(), QMacPasteboardMimeUrl::convertFromMime(), QNetworkCookieJar::cookiesForUrl(), QNetworkAccessFileBackendFactory::create(), QNetworkAccessFtpBackendFactory::create(), QNetworkAccessHttpBackendFactory::create(), createPixmapDataSync(), QNetworkAccessManager::createRequest(), QTextBrowserPrivate::findFile(), QDeclarativeXMLHttpRequest::finished(), fromUserInput(), QWindowsSystemProxy::init(), isParentOf(), launchWebBrowser(), QDeclarativePixmap::load(), QTextDocument::loadResource(), QDeclarativeComponent::loadUrl(), lsOpen(), makeCacheKey(), QNetworkAccessFileBackend::open(), QDesktopServices::openUrl(), parseHeaderValue(), QNetworkAccessHttpBackend::postRequest(), QDeclarativePixmapReader::processJob(), QNetworkProxyQuery::protocolTag(), proxyAuthenticationKey(), qDecodeDataUrl(), QNetworkReplyFileImpl::QNetworkReplyFileImpl(), registerComponent(), resolveScheme(), QTextBrowserPrivate::resolveUrl(), setScheme(), QNetworkProxyFactory::systemProxyForQuery(), toLocalFile(), and QDeclarativeEnginePrivate::urlToLocalFileOrQrc().
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:
Definition at line 4575 of file qurl.cpp.
void QUrl::setEncodedFragment | ( | const QByteArray & | fragment | ) |
Sets the URL's fragment to the percent-encoded 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:
The fragment is sometimes also referred to as the URL "reference".
Passing an argument of QByteArray() (a null QByteArray) will unset the fragment. Passing an argument of QByteArray("") (an empty but not null QByteArray) will set the fragment to an empty string (as if the original URL had a lone "#").
Definition at line 5727 of file qurl.cpp.
void QUrl::setEncodedHost | ( | const QByteArray & | host | ) |
Sets the URL's host to the ACE- or percent-encoded host.
The host is part of the user info element in the authority of the URL, as described in setAuthority().
Definition at line 4861 of file qurl.cpp.
void QUrl::setEncodedPassword | ( | const QByteArray & | password | ) |
Sets the URL's password to the percent-encoded password.
The password is part of the user info element in the authority of the URL, as described in setUserInfo().
Note: this function does not verify that password is properly encoded. It is the caller's responsibility to ensure that the any delimiters (such as colons or slashes) are properly encoded.
Definition at line 4780 of file qurl.cpp.
void QUrl::setEncodedPath | ( | const QByteArray & | path | ) |
Sets the URL's path to the percent-encoded path.
The path is the part of the URL that comes after the authority but before the query string.
For non-hierarchical schemes, the path will be everything following the scheme declaration, as in the following example:
Note: this function does not verify that path is properly encoded. It is the caller's responsibility to ensure that the any delimiters (such as '?' and '#') are properly encoded.
Definition at line 5013 of file qurl.cpp.
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 "?".
Definition at line 5136 of file qurl.cpp.
Referenced by makeCacheKey().
void QUrl::setEncodedQueryItems | ( | const QList< QPair< QByteArray, QByteArray > > & | query | ) |
Sets the query string of the URL to the 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().
Note: this function does not verify that the key-value pairs are properly encoded. It is the caller's responsibility to ensure that the query delimiters are properly encoded, if any.
Definition at line 5205 of file qurl.cpp.
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.
Definition at line 4429 of file qurl.cpp.
Referenced by fromEncoded().
void QUrl::setEncodedUrl | ( | const QByteArray & | url, |
ParsingMode | mode | ||
) |
Constructs a URL by parsing the contents of encodedUrl using the given parsingMode.
Definition at line 4449 of file qurl.cpp.
void QUrl::setEncodedUserName | ( | const QByteArray & | userName | ) |
Sets the URL's user name to the percent-encoded userName.
The userName is part of the user info element in the authority of the URL, as described in setUserInfo().
Note: this function does not verify that userName is properly encoded. It is the caller's responsibility to ensure that the any delimiters (such as colons or slashes) are properly encoded.
Definition at line 4694 of file qurl.cpp.
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:
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 "#").
Definition at line 5669 of file qurl.cpp.
Referenced by authenticationKey(), QPatternist::ReportContext::codeFromURI(), proxyAuthenticationKey(), qmlxmlhttprequest_open(), resolved(), QTextBrowserPrivate::setSource(), QNetworkCacheMetaData::setUrl(), and QNetworkDiskCachePrivate::uniqueFileName().
void QUrl::setHost | ( | const QString & | host | ) |
Sets the host of the URL to host.
The host is part of the authority.
Definition at line 4821 of file qurl.cpp.
Referenced by QHttpPrivate::_q_slotSendRequest(), QMacPasteboardMimeFileUri::convertFromMime(), QMacPasteboardMimeUrl::convertFromMime(), QMacPasteboardMimeFileUri::convertToMime(), QMacPasteboardMimeUrl::convertToMime(), fromLocalFile(), makeCacheKey(), QNetworkAccessFileBackend::open(), proxyAuthenticationKey(), QNetworkReplyFileImpl::QNetworkReplyFileImpl(), setEncodedHost(), QNetworkProxyQuery::setPeerHostName(), and QNetworkProxyFactory::systemProxyForQuery().
|
static |
Sets the whitelist of Top-Level Domains (TLDs) that are allowed to have non-ASCII characters in domains to the value of list.
Note that if you call this function, you need to do so before you start any threads that might access idnWhitelist().
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 6212 of file qurl.cpp.
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().
Definition at line 4736 of file qurl.cpp.
Referenced by qmlxmlhttprequest_open(), QNetworkCacheMetaData::setUrl(), and QNetworkDiskCachePrivate::uniqueFileName().
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.
For non-hierarchical schemes, the path will be everything following the scheme declaration, as in the following example:
Definition at line 4960 of file qurl.cpp.
Referenced by QMacPasteboardMimeFileUri::convertFromMime(), QMacPasteboardMimeUrl::convertFromMime(), QMacPasteboardMimeFileUri::convertToMime(), QMacPasteboardMimeUrl::convertToMime(), fromLocalFile(), isParentOf(), QNetworkAccessFileBackend::open(), QNetworkAccessFtpBackend::open(), and QNetworkReplyFileImpl::QNetworkReplyFileImpl().
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 4897 of file qurl.cpp.
Referenced by QHttpPrivate::_q_slotSendRequest(), makeCacheKey(), proxyAuthenticationKey(), QNetworkProxyQuery::setPeerPort(), and QHttpThreadDelegate::startRequest().
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 '&'.
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:
Calling this function does not change the delimiters of the current query string. It only affects queryItems(), setQueryItems() and addQueryItems().
Definition at line 5089 of file qurl.cpp.
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().
Definition at line 5161 of file qurl.cpp.
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":
The scheme can also be empty, in which case the URL is interpreted as relative.
Definition at line 4533 of file qurl.cpp.
Referenced by QHttpPrivate::_q_slotSendRequest(), QMacPasteboardMimeFileUri::convertFromMime(), QMacPasteboardMimeUrl::convertFromMime(), fromLocalFile(), QWindowsSystemProxy::init(), QTextDocument::loadResource(), makeCacheKey(), proxyAuthenticationKey(), resolved(), QNetworkProxyQuery::setProtocolTag(), and QNetworkProxyFactory::systemProxyForQuery().
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.
Definition at line 4358 of file qurl.cpp.
Referenced by QUrl().
void QUrl::setUrl | ( | const QString & | url, |
ParsingMode | parsingMode | ||
) |
Parses url using the parsing mode parsingMode.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 4373 of file qurl.cpp.
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:
Definition at line 4615 of file qurl.cpp.
Referenced by QNetworkAccessFtpBackend::ftpDone(), and QHttpNetworkConnectionChannel::sendRequest().
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().
Definition at line 4648 of file qurl.cpp.
Referenced by QNetworkAccessAuthenticationManager::cacheCredentials(), QNetworkAccessFtpBackend::ftpDone(), makeCacheKey(), proxyAuthenticationKey(), and qmlxmlhttprequest_open().
|
inline |
|
static |
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 "example.com"
) to be written using international characters.
This function return an empty QByteArra if domain is not a valid hostname. Note, in particular, that IPv6 literals are not valid domain names.
Definition at line 6158 of file qurl.cpp.
Referenced by encodedHost(), QHostInfoAgent::fromName(), QSslSocketBackendPrivate::initSslContext(), QNetworkCookiePrivate::parseSetCookieHeaderLine(), QHttpNetworkConnectionPrivate::prepareRequest(), qt_socks5_set_host_name_and_port(), QHttpSocketEngine::slotSocketConnected(), QUrlPrivate::toEncoded(), QNetworkCookie::toRawForm(), and translateWSAError().
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 5949 of file qurl.cpp.
Referenced by QHttpPrivate::_q_slotSendRequest(), authenticationKey(), QMacPasteboardMimeFileUri::convertFromMime(), QMacPasteboardMimeUrl::convertFromMime(), QHttpThreadDelegate::finishedSlot(), QPatternist::ColoringMessageHandler::handleMessage(), headerValue(), launch(), launchWebBrowser(), lsOpen(), macQueryInternal(), makeCacheKey(), operator<<(), proxyAuthenticationKey(), qDecodeDataUrl(), qHash(), QNetworkReplyDataImpl::QNetworkReplyDataImpl(), resolved(), QMimeDataPrivate::retrieveTypedData(), QHttpThreadDelegate::synchronousFinishedSlot(), QNetworkProxyFactory::systemProxyForQuery(), QTest::toString(), QNetworkDiskCachePrivate::uniqueFileName(), and QHttpNetworkRequestPrivate::uri().
QString QUrl::toLocalFile | ( | ) | const |
Returns the path of this URL formatted as a local file path.
The path returned will use forward slashes, even if it was originally created from one with backslashes.
If this URL contains a non-empty hostname, it will be encoded in the returned value in the form found on SMB networks (for example, "//servername/path/to/file.txt").
If this is a relative URL, in Qt 4.x this function returns the path to maintain backward compatability. This will change from 5.0 onwards. Then the path is returned only for URLs where the scheme is "file", and for all other URLs an empty string is returned.
Definition at line 6412 of file qurl.cpp.
Referenced by QFileDialogPrivate::_q_goToDirectory(), QFileDialogPrivate::_q_goToUrl(), QUrlModel::addUrls(), QWindowsMimeURI::canConvertFromMime(), QUrlModel::canDrop(), QUrlModel::changed(), QDeclarativeFolderListModel::componentComplete(), QWindowsMimeURI::convertFromMime(), QTextBrowserPrivate::findFile(), QTextDocument::loadResource(), QNetworkAccessFileBackend::open(), openDocument(), QFileOpenEvent::QFileOpenEvent(), QNetworkReplyFileImpl::QNetworkReplyFileImpl(), QDeclarativeFolderListModel::refresh(), QTextBrowserPrivate::resolveUrl(), QUrlModel::setData(), QDeclarativeFolderListModel::setFolder(), QUrlModel::setUrl(), and QDeclarativeEnginePrivate::urlToLocalFileOrQrc().
|
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 / "-" / "." / "_" / "~"
Definition at line 6009 of file qurl.cpp.
Referenced by allQueryItemValues(), QPatternist::EncodeString::evaluateSingleton(), hasQueryItem(), queryItemValue(), removeAllQueryItems(), removeQueryItem(), swap(), and QNetworkCookie::toRawForm().
QString QUrl::topLevelDomain | ( | ) | const |
Returns the TLD (Top-Level Domain) of the URL, (e.
g. .co.uk, .net). Note that the return value is prefixed with a '.' unless the URL does not contain a valid TLD, in which case the function returns an empty string.
Definition at line 5794 of file qurl.cpp.
|
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 6025 of file qurl.cpp.
Returns the human-displayable string representation of the URL.
The output can be customized by passing flags with options.
Definition at line 5896 of file qurl.cpp.
Referenced by QTextBrowserPrivate::_q_highlightLink(), QDeclarativeImportsPrivate::add(), QPatternist::ReportContext::codeFromURI(), QDeclarativeTypeData::compile(), QDeclarativeCompiler::compileTree(), QDeclarativeConnections::connectSignals(), QWindowsMimeURI::convertFromMime(), QNetworkAccessFileBackendFactory::create(), createPixmapDataSync(), QDeclarativeEnginePrivate::createQmlObject(), QPatternist::URILoader::createRequest(), QDeclarativeTypeData::done(), QDeclarativeCompiler::dumpStats(), QDeclarativeComponent::errorString(), QDeclarativeImportedNamespace::find(), QTextHtmlExporter::findUrlForImage(), QDeclarativeInclude::finished(), QDeclarativeXMLHttpRequest::finished(), QTextBrowser::focusNextPrevChild(), QPatternist::formatResourcePath(), QPatternist::formatURI(), QPatternist::AtomicString::fromValue(), QPatternist::AnyURI::fromValue(), getImage(), QDeclarativeEnginePrivate::getImageFromProvider(), getPixmap(), QDeclarativeEnginePrivate::getPixmapFromProvider(), QDeclarativeInclude::include(), QWindowsSystemProxy::init(), launchWebBrowser(), QPatternist::NetworkAccessDelegator::managerFor(), QDeclarativeVMEMetaObject::method(), navigatorInvoke(), QNetworkAccessFileBackend::open(), QNetworkAccessFtpBackend::open(), openDocument(), operator<<(), QDeclarativeScriptParser::parse(), QPatternist::AccelTree::printStats(), QDeclarativePixmapReader::processJob(), QDeclarativeWorkerScriptEnginePrivate::processLoad(), QSourceLocation::qHash(), QNetworkReplyFileImpl::QNetworkReplyFileImpl(), QDeclarativeDebugTrace::rangeDataImpl(), QDeclarativeDebugTrace::rangeLocationImpl(), readImage(), registerComponent(), QDeclarativeXMLHttpRequest::requestFromUrl(), QPatternist::resolveAndCheckCollation(), QDeclarativeScriptEngine::resolvedUrl(), resolveScheme(), QPatternist::AnyURI::resolveURI(), QTextBrowserPrivate::restoreHistoryEntry(), QDeclarativeEngineDebugService::setMethodBody(), QTextBrowserPrivate::setSource(), statusCodeFromHttp(), QNetworkProxyFactory::systemProxyForQuery(), QDeclarativeError::toString(), QPatternist::AtomicValue::toXDM(), and QPatternist::DefaultCollationFN::typeCheck().
QString QUrl::userInfo | ( | ) | const |
Returns the user info of the URL, or an empty string if the user info is undefined.
Definition at line 4631 of file qurl.cpp.
Referenced by QHttpNetworkConnectionPrivate::fillPipeline(), and QHttpNetworkConnectionChannel::sendRequest().
QString QUrl::userName | ( | ) | const |
Returns the user name of the URL if it is defined; otherwise an empty string is returned.
Definition at line 4667 of file qurl.cpp.
Referenced by QNetworkAccessManagerPrivate::authenticationRequired(), QNetworkAccessAuthenticationManager::cacheCredentials(), QNetworkAccessFtpBackend::open(), QHttpNetworkConnectionChannel::sendRequest(), setEncodedUserName(), and setUserName().
|
related |
Writes url url to the stream out and returns a reference to the stream.
Definition at line 6757 of file qurl.cpp.
Referenced by operator<<().
|
related |
Reads a url into url from the stream in and returns a reference to the stream.
Definition at line 6774 of file qurl.cpp.
Computes a hash key from the normalized version of url.
Definition at line 285 of file qurl.h.
Referenced by containsTLDEntry(), getLock(), and qHash().
|
private |
Definition at line 279 of file qurl.h.
Referenced by addEncodedQueryItem(), addQueryItem(), allEncodedQueryItemValues(), allQueryItemValues(), authority(), clear(), detach(), encodedFragment(), encodedPassword(), encodedPath(), encodedQuery(), encodedQueryItems(), encodedQueryItemValue(), encodedUserName(), errorString(), fragment(), hasEncodedQueryItem(), hasFragment(), hasQuery(), hasQueryItem(), host(), isDetached(), isEmpty(), isLocalFile(), isParentOf(), isRelative(), isValid(), operator<(), operator=(), operator==(), password(), path(), port(), queryItems(), queryItemValue(), queryPairDelimiter(), queryValueDelimiter(), QUrl(), removeAllEncodedQueryItems(), removeAllQueryItems(), removeEncodedQueryItem(), removeQueryItem(), resolved(), scheme(), setAuthority(), setEncodedFragment(), setEncodedPassword(), setEncodedPath(), setEncodedQuery(), setEncodedQueryItems(), setEncodedUrl(), setEncodedUserName(), setFragment(), setHost(), setPassword(), setPath(), setPort(), setQueryDelimiters(), setQueryItems(), setScheme(), setUrl(), setUserInfo(), setUserName(), swap(), toEncoded(), toLocalFile(), toString(), userInfo(), userName(), and ~QUrl().