QUrl Class Reference |
Constant | Value | Description |
---|---|---|
QUrl::None | 0x0 | The URL is left unchanged. |
QUrl::RemoveScheme | 0x1 | The scheme is removed from the URL. |
QUrl::RemovePassword | 0x2 | Any password in the URL is removed. |
QUrl::RemoveUserInfo | RemovePassword | 0x4 | Any user information in the URL is removed. |
QUrl::RemovePort | 0x8 | Any specified port is removed from the URL. |
QUrl::RemoveAuthority | RemoveUserInfo | RemovePort | 0x10 | |
QUrl::RemovePath | 0x20 | The URL's path is removed, leaving only the scheme, host address, and port (if present). |
QUrl::RemoveQuery | 0x40 | The query part of the URL (following a '?' character) is removed. |
QUrl::RemoveFragment | 0x80 | |
QUrl::StripTrailingSlash | 0x10000 | The trailing slash is removed if one is present. |
The FormattingOptions type is a typedef for QFlags<FormattingOption>. It stores an OR combination of FormattingOption values.
The parsing mode controls the way QUrl parses strings.
Constant | Value | Description |
---|---|---|
QUrl::TolerantMode | 0 | QUrl will try to correct some common errors in URLs. This mode is useful when processing URLs entered by users. |
QUrl::StrictMode | 1 | Only valid URLs are accepted. This mode is useful for general URL validation. |
In TolerantMode, the parser corrects the following invalid input:
Constructs an empty QUrl object.
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%20of%20holidays.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(), and TolerantMode.
Constructs a copy of other.
Parses the url using the parser mode parsingMode.
See also setUrl().
Destructor; called immediately before the object is deleted.
Inserts the pair key = value into the query string of the URL.
Returns the a list of query string values whose key is equal to key from the URL.
See also queryItemValue().
Returns the authority of the URL if it is defined; otherwise an empty string is returned.
See also setAuthority().
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.
Returns the query string of the URL in percent encoded form.
See also setEncodedQuery().
Returns a text string that explains why an URL is invalid in the case being; otherwise returns an empty string.
This function was introduced in Qt 4.2.
Returns the fragment of the URL.
See also setFragment().
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.
This function was introduced in Qt 4.2.
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() and setUrl().
This is an overloaded member function, provided for convenience.
Parses the URL using parsingMode.
See also toEncoded() and setUrl().
Returns a QUrl representation of localFile, interpreted as a local file.
See also toLocalFile().
Returns a decoded copy of input. input is first decoded from percent encoding, then converted from UTF-8 to unicode.
Returns true if this URL contains a fragment (i.e., if # was seen on it).
This function was introduced in Qt 4.2.
See also fragment() and setFragment().
Returns true if this URL contains a Query (i.e., if ? was seen on it).
This function was introduced in Qt 4.2.
See also hasQueryItem() and encodedQuery().
Returns true if there is a query string pair whose key is equal to key from the URL.
Returns the host of the URL if it is defined; otherwise an empty string is returned.
See also setHost().
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.
This function was introduced in Qt 4.2.
See also setIdnWhitelist().
Returns true if the URL has no data; otherwise returns false.
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.
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().
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; }
Returns the password of the URL if it is defined; otherwise an empty string is returned.
See also setPassword() and setUserName().
Returns the path of the URL.
See also setPath().
Returns the port of the URL, or -1 if the port is unspecified.
See also setPort().
This is an overloaded member function, provided for convenience.
Returns the port of the URL, or defaultPort if the port is unspecified.
Example:
QFtp ftp; ftp.connectToHost(url.host(), url.port(21));
This function was introduced in Qt 4.1.
Returns the first query string value whose key is equal to key from the URL.
See also allQueryItemValues().
Returns the query string of the URL, as a map of keys and values.
See also setQueryItems() and setEncodedQuery().
Returns the character used to delimit between key-value pairs in the query string of the URL.
Returns the character used to delimit between keys and values in the query string of the URL.
Removes all the query string pairs whose key is equal to key from the URL.
See also removeQueryItem().
Removes the first query string pair whose key is equal to key from the URL.
See also removeAllQueryItems().
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().
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() and isRelative().
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:
See also authority().
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() and hasQuery().
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().
This is an overloaded member function, provided for convenience.
Constructs a URL by parsing the contents of encodedUrl using the given parsingMode.
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 "#").
See also fragment() and hasFragment().
Sets the host of the URL to host. The host is part of the authority.
See also host() and setAuthority().
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.
This function was introduced in Qt 4.2.
See also idnWhitelist().
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() and setUserInfo().
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:
See also path().
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.
See also port().
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:
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().
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() and queryItems().
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.
See also scheme() and isRelative().
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().
This is an overloaded member function, provided for convenience.
Parses url using the parsing mode parsingMode.
See also setEncodedUrl().
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:
See also userInfo(), setUserName(), setPassword(), and setAuthority().
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() and setUserInfo().
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.
This function was introduced in Qt 4.2.
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.
Returns the path of this URL formatted as a local file path.
See also fromLocalFile().
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}"
Returns the human-displayable string representation of the URL. The output can be customized by passing flags with options.
See also FormattingOptions and toEncoded().
Returns the user info of the URL, or an empty string if the user info is undefined.
See also setUserInfo().
Returns the user name of the URL if it is defined; otherwise an empty string is returned.
See also setUserName().
Returns true if this URL and the given url are not equal; otherwise returns false.
Assigns the specified url to this object.
This is an overloaded member function, provided for convenience.
Assigns the specified url to this object.
Returns true if this URL and the given url are equal; otherwise returns false.
This is an overloaded member function, provided for convenience.
Writes url url to the stream out and returns a reference to the stream.
See also Format of the QDataStream operators.
This is an overloaded member function, provided for convenience.
Reads a url into url from the stream in and returns a reference to the stream.
See also Format of the QDataStream operators.
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 4.3 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com