CopperSpice API  1.9.2
QUrl Class Reference

The QUrl class provides an interface for working with URL syntax. More...

Public Typedefs

using FormattingOptions = QFlags< FormattingOption >
 
using UserInputResolutionOptions = QFlags< UserInputResolutionOption >
 

Public Types

enum  FormattingOption
 
enum  ParsingMode
 
enum  UserInputResolutionOption
 

Public Methods

 QUrl ()
 
 QUrl (const QString &url, ParsingMode mode=TolerantMode)
 
 QUrl (const QUrl &other)
 
 QUrl (QUrl &&other)
 
 ~QUrl ()
 
void addEncodedQueryItem (const QByteArray &key, const QByteArray &value)
 
void addQueryItem (const QString &key, const QString &value)
 
QUrl adjusted (FormattingOptions options) const
 
QList< QByteArrayallEncodedQueryItemValues (const QByteArray &key) const
 
QStringList allQueryItemValues (const QString &key) const
 
QString authority (FormattingOptions options=PrettyDecoded) const
 
void clear ()
 
QByteArray encodedFragment () const
 
QByteArray encodedHost () const
 
QByteArray encodedPassword () const
 
QByteArray encodedPath () const
 
QByteArray encodedQuery () const
 
QList< QPair< QByteArray, QByteArray > > encodedQueryItems () const
 
QByteArray encodedQueryItemValue (const QByteArray &key) const
 
QByteArray encodedUserName () const
 
QString errorString () const
 
QString fileName (FormattingOptions options=FullyDecoded) const
 
QString fragment (FormattingOptions options=PrettyDecoded) const
 
bool hasEncodedQueryItem (const QByteArray &key) const
 
bool hasFragment () const
 
bool hasQuery () const
 
bool hasQueryItem (const QString &key) const
 
QString host (FormattingOptions options=FullyDecoded) const
 
bool isEmpty () const
 
bool isLocalFile () const
 
bool isParentOf (const QUrl &url) const
 
bool isRelative () const
 
bool isValid () const
 
bool matches (const QUrl &url, FormattingOptions options) const
 
bool operator!= (const QUrl &url) const
 
bool operator< (const QUrl &url) const
 
QUrl & operator= (const QUrl &other)
 
QUrl & operator= (QUrl &&other)
 
bool operator== (const QUrl &url) const
 
QString password (FormattingOptions options=FullyDecoded) const
 
QString path (FormattingOptions options=FullyDecoded) const
 
int port (int defaultPort=-1) const
 
QString query (FormattingOptions options=PrettyDecoded) const
 
QList< QPair< QString, QString > > queryItems () const
 
QString queryItemValue (const QString &key) const
 
void removeAllEncodedQueryItems (const QByteArray &key)
 
void removeAllQueryItems (const QString &key)
 
void removeEncodedQueryItem (const QByteArray &key)
 
void removeQueryItem (const QString &key)
 
QUrl resolved (const QUrl &relative) const
 
QString scheme () const
 
void setAuthority (const QString &authority, ParsingMode mode=TolerantMode)
 
void setEncodedFragment (const QByteArray &fragment)
 
void setEncodedHost (const QByteArray &host)
 
void setEncodedPassword (const QByteArray &password)
 
void setEncodedPath (const QByteArray &path)
 
void setEncodedQuery (const QByteArray &query)
 
void setEncodedQueryItems (const QList< QPair< QByteArray, QByteArray >> &query)
 
void setEncodedUrl (const QByteArray &url, ParsingMode parsingMode=TolerantMode)
 
void setEncodedUserName (const QByteArray &userName)
 
void setFragment (const QString &fragment, ParsingMode mode=TolerantMode)
 
void setHost (const QString &host, ParsingMode mode=DecodedMode)
 
void setPassword (const QString &password, ParsingMode mode=DecodedMode)
 
void setPath (const QString &path, ParsingMode mode=DecodedMode)
 
void setPort (int port)
 
void setQuery (const QString &query, ParsingMode mode=TolerantMode)
 
void setQuery (const QUrlQuery &query)
 
void setQueryItems (const QList< QPair< QString, QString >> &query)
 
void setScheme (const QString &scheme)
 
void setUrl (const QString &url, ParsingMode mode=TolerantMode)
 
void setUserInfo (const QString &userInfo, ParsingMode mode=TolerantMode)
 
void setUserName (const QString &userName, ParsingMode mode=DecodedMode)
 
void swap (QUrl &other)
 
CFURLRef toCFURL () const
 
QString toDisplayString (FormattingOptions options=FormattingOptions (PrettyDecoded)) const
 
QByteArray toEncoded (FormattingOptions options=FullyEncoded) const
 
QString toLocalFile () const
 
NSURL * toNSURL () const
 
QString topLevelDomain (FormattingOptions options=FullyDecoded) const
 
QString toString (FormattingOptions options=FormattingOptions (PrettyDecoded)) const
 
QString url (FormattingOptions options=FormattingOptions (PrettyDecoded)) const
 
QString userInfo (FormattingOptions options=PrettyDecoded) const
 
QString userName (FormattingOptions options=FullyDecoded) const
 

Static Public Methods

static QString fromAce (const QByteArray &domain)
 
static QString fromAce (const QString &domain)
 
static QUrl fromCFURL (CFURLRef url)
 
static QUrl fromEncoded (const QByteArray &url, ParsingMode mode=TolerantMode)
 
static QUrl fromLocalFile (const QString &localfile)
 
static QUrl fromNSURL (const NSURL *url)
 
static QString fromPercentEncoding (const QByteArray &input)
 
static QString fromPunycode (const QByteArray &punycode)
 
static QList< QUrl > fromStringList (const QStringList &urls, ParsingMode mode=TolerantMode)
 
static QUrl fromUserInput (const QString &userInput)
 
static QUrl fromUserInput (const QString &userInput, const QString &workingDirectory, UserInputResolutionOptions options=DefaultResolution)
 
static QStringList idnWhitelist ()
 
static void setIdnWhitelist (const QStringList &list)
 
static QByteArray toAce (const QString &domain)
 
static QByteArray toPercentEncoding (const QString &input, const QByteArray &exclude=QByteArray (), const QByteArray &include=QByteArray ())
 
static QByteArray toPunycode (const QString &string)
 
static QStringList toStringList (const QList< QUrl > &urls, FormattingOptions options=FormattingOptions (PrettyDecoded))
 

Friends

class QUrlQuery
 

Related Functions

These are not member functions

QDataStreamoperator<< (QDataStream &stream, const QUrl &url)
 
QDataStreamoperator>> (QDataStream &steam, QUrl &url)
 
uint qHash (const QUrl &url, uint seed=0)
 

Detailed Description

The QUrl class provides an interface for working with URL syntax. QUrl also has support for internationalized domain names (IDNs). This class can parse and construct a URL and supports both raw and encoded formats. The raw format referred to as unencoded is the human readable form. The encoded format is used when implementing HTTP.

QUrl can be initialized by passing a QString to its constructor. The methods setUrl() and setEncodedUrl() can then be used to set the URL name. A URL can also be constructed by calling setScheme(), setUserName(), setPassword(), setHost(), setPort(), setPath(), setEncodedQuery() and setFragment().

The following two methods provide the ability to set multiple values at the same time.

The method isValid() can be used to check if the URL is valid before it is used. This can be done at any point during the constructing of a URL.

Constructing a query is accomplished by using the QUrlQuery class and the methods QUrlQuery::setQueryItems(), QUrlQuery::addQueryItem() and QUrlQuery::removeQueryItem(). Use QUrlQuery::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 methods called fromPercentEncoding() and toPercentEncoding() which deal with percent encoding and decoding of a QString.

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.

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

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)).

Character Conversions

Calling isRelative() will return whether or not the URL is relative. A relative URL has no scheme.

qDebug() << QUrl("main.txt").isRelative(); // true: no scheme
qDebug() << QUrl("txt/main.txt").isRelative(); // true: no scheme
qDebug() << QUrl("file:main.txt").isRelative(); // false: has "file" scheme
qDebug() << QUrl("file:txt/main.txt").isRelative(); // false: has "file" scheme

Notice that a URL can be absolute while containing a relative path, and vice versa.

QUrl url("file:file.txt"); // absolute URL, relative path
qDebug() << url.isRelative(); // false: has "file" scheme
qDebug() << QDir::isAbsolutePath(url.path()); // false: relative path
url = QUrl("/home/user/file.txt"); // relative URL, absolute path
qDebug() << url.isRelative(); // true: has no scheme
qDebug() << QDir::isAbsolutePath(url.path()); // true: absolute path

A relative URL can be resolved by passing it as an argument to resolved() which returns an absolute URL. The method isParentOf() is used for determining whether one URL is a parent of another.

Error Checking

QUrl is capable of detecting many errors in URLs while parsing it or when components of the URL are set with individual setter methods (like setScheme(), setHost() or setPath()). If the parsing or setter function is successful, any previously recorded error conditions will be discarded.

By default the QUrl setter methods operate in QUrl::TolerantMode which means they accept some common mistakes which can misrepresent the data. An alternate method for parsing is QUrl::StrictMode which applies further checks. Refer to QUrl::ParsingMode for a description of the differences.

QUrl only checks for conformance with the URL specification. It does not try to verify that high-level protocol URLs are in the format they are expected to be by handlers elsewhere. For example, the following URIs are all considered valid by QUrl, even if they do not make sense when used:

  • "http:/filename.html"
  • "mailto://example.com"

When the parser encounters an error it signals the event by making isValid() return false and toString() / toEncoded() return an empty string. If it is necessary to show the user the reason why the URL failed to parse, the error condition can be obtained from QUrl by calling errorString(). This message is highly technical and may not make sense to end users.

QUrl is capable of recording only one error condition. If more than one error is found it is undefined which error is reported.

Character Conversions

Follow these rules to avoid erroneous character conversion when dealing with URLs and strings:

Member Typedef Documentation

Typedef for QFlags<FormattingOption> which contains an OR combination of FormattingOption values.

Refer to QUrl::FormattingOption for the enum documentation.

Typedef for QFlags<UserInputResolutionOption> which contains an OR combination of UserInputResolutionOption values.

Refer to QUrl::UserInputResolutionOption for the enum documentation.

Member Enumeration Documentation

The formatting options define how the components of an URL will be formatted when written out as text. They can be combined with the options from QUrl::FormattingOptions when used in toString() and toEncoded().

ConstantValueDescription
QUrl::None 0x0 Format of the URL is unchanged
QUrl::RemoveScheme 0x1 Scheme is removed from the URL
QUrl::RemovePassword 0x2 Passwords in the URL are removed
QUrl::RemoveUserInfo RemovePassword
| 0x4
Any user information in the URL is removed
QUrl::RemovePort 0x8 Specified port is removed from the URL
QUrl::RemoveAuthority RemoveUserInfo
| RemovePort
| 0x1
QUrl::RemovePath 0x20 Path is removed leaving only the scheme, host address, and port
QUrl::RemoveQuery 0x40 Query part of the URL (text following a ? character) is removed
QUrl::RemoveFragment 0x80
QUrl::PreferLocalFile 0x200 If isLocalFile() is true and there is no query or fragment, a local file path is returned
QUrl::StripTrailingSlash 0x400 Trailing slash is removed if one is present
QUrl::RemoveFilename 0x800 Everything after the last "/" in the path is removed, trailing "/" is kept, only valid if RemovePath is not set
QUrl::NormalizePathSegments 0x1000
QUrl::PrettyDecoded 0x000000 Returned in a pretty form with some percent encoded characters decoded, exact behavior varies by component and may also change in a future release
QUrl::EncodeSpaces 0x100000 Leave space characters in their encoded form ("%20")
QUrl::EncodeUnicode 0x200000 Leave non-US-ASCII characters encoded in their UTF-8 percent encoded form
QUrl::EncodeDelimiters 0x400000
| 0x800000
Leave certain delimiters in their encoded form, as it would appear in the URL when the full URL is represented as text. The delimiters are affected by this option change. This flag has no effect in toString() or toEncoded()
QUrl::EncodeReserved 0x100000 Leave US-ASCII characters not permitted in the URL by the specification in their encoded form. This is the default on toString() and toEncoded()
QUrl::DecodeReserved 0x200000 Decode the US-ASCII characters that the URL specification does not allow to appear in the URL. This is the default on the getters of individual components
QUrl::FullyEncoded EncodeSpaces
| EncodeUnicode
| EncodeDelimiters
EncodeReserved
Leave all characters in their properly-encoded form as it would appear as part of a URL. When used with toString() this produces a fully-compliant URL in QString form, exactly equal to the result of toEncoded()
QUrl::FullyDecoded FullyEncoded
| DecodeReserved
| 0x4000000
Attempt to decode as much as possible. For individual components of the URL, this decodes every percent encoding sequence, including control characters (U+0000 to U+001F) and UTF-8 sequences found in percent encoded form. Use of this mode may cause data loss, see below for more

The values of EncodeReserved and DecodeReserved should not be used together in one call. This behavior is undefined. They are provided as separate values because the behavior of the pretty mode with regards to reserved characters is different on certain components and specially on the full URL.

Full decoding

In the FullyDecoded mode every character represents itself and never has any special meaning. This is true even for the percent character which should be interpreted to mean a literal percent, not the beginning of a percent encoded sequence. The same character in all decoding modes, is represented by the sequence "%25".

When re-applying data obtained with QUrl::FullyDecoded into a QUrl, care must be taken to use the QUrl::DecodedMode parameter to the setters (like setPath() and setUserName()). Failure to do so may cause re-interpretation of the percent character as the beginning of a percent encoded sequence.

This mode is quite useful when portions of a URL are used in a non-URL context. For example, to extract the user name, password or file paths in an FTP client application, the FullyDecoded mode should be used.

This mode should be used with care, since there are two conditions that cannot be reliably represented in the returned QString. They are:

  • Non-UTF-8 sequences: A URL may contain sequences of percent encoded characters that do not form valid UTF-8 sequences. Any invalid sequence will result in the QString containing replacement characters where the sequence existed.
  • Encoded delimiters: A URL is also allowed to make a distinction between a delimiter found in its literal form and its equivalent in percent encoded form. This is most commonly found in the query but is permitted in most parts of the URL.

Example

The following example illustrates a potential problem with the fully decoded mode.

QUrl original("http://example.com/?q=a%2B%3Db%26c");
QUrl copy(original);
copy.setQuery(copy.query(QUrl::FullyDecoded), QUrl::DecodedMode);
qDebug() << original.toString(); // prints: "http://example.com/?q=a%2B%3Db%26c"
qDebug() << copy.toString(); // prints: "http://example.com/?q=a+=b&c"

If the two URLs were used via HTTP GET, the interpretation by the web server would probably be different. In the first case, it would interpret as one parameter, with a key of "q" and value "a+=b&c". In the second case, it would probably interpret as two parameters, one with a key of "q" and value "a =b", and the second with a key "c" and no value.

See also
QUrl::FormattingOptions

The parsing mode controls the way QUrl parses strings.

ConstantValueDescription
QUrl::TolerantMode0 QUrl will try to correct some common errors in URLs. This mode is useful when processing URLs entered by users.
QUrl::StrictMode1 Only valid URLs are accepted. This mode is useful for general URL validation.
QUrl::DecodeMode2 QUrl will interpret the URL component in the fully-decoded form, where percent characters stand for themselves, not as the beginning of a percent encoded sequence. This mode is only valid for the setters setting components of a URL, it is not permitted in the QUrl constructor, in fromEncoded() or in setUrl(). For more information on this mode, see the documentation for QUrl::FullyDecoded.

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 "%": Any occurrences of a percent character not followed by exactly two hexadecimal characters. For example, "13% coverage.html" will be replaced by "13%25 coverage.html".
  • Reserved and UnReserved characters: An encoded URL should only contain certain characters. All other characters should be percent encoded. The following characters will automatically be percent encoded where necessary.

                 space double-quote < > [ ] { } / ^ ' " ; |


TolerantMode is not usually enough for parsing user input which often contains more errors and expectations than the parser can deal with. When dealing with data coming directly from the user, as opposed to data coming from data-transfer sources such as other programs, it is recommended to use fromUserInput().

In StrictMode if a parsing error is found, isValid() will return false and errorString() will return a message describing the error. If more than one error is detected, it is undefined which error gets reported.

See also
fromUserInput(), setUrl(), toString(), toEncoded(), QUrl::FormattingOptions

The user input resolution options define how fromUserInput() should interpret strings that could either be a relative path or the short form of a HTTP URL. For instance file.pl can be either a local file or the URL http://file.pl.

ConstantValueDescription
QUrl::DefaultResolution 0 Default resolution mechanism is to check whether a local file exists, in the working directory given to fromUserInput, and only return a local path in that case. Otherwise a URL is assumed.
QUrl::AssumeLocalFile 1 Method fromUserInput() will always return a local path unless the input contains a scheme, such as http://file.pl. This is useful for applications such as text editors which are able to create the file if it does not exist.
See also
fromUserInput()

Constructor & Destructor Documentation

QUrl::QUrl ( )

Constructs an empty QUrl object.

QUrl::QUrl ( const QUrl &  other)

Copy constructs a new QUrl from other.

QUrl::QUrl ( const QString url,
ParsingMode  mode = TolerantMode 
)
explicit

Constructs a URL by parsing url. The 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.

Parses the url using the given parser mode.

In TolerantMode QUrl will correct certain mistakes, notably the presence of a percent character not followed by two hexadecimal digits, and it will accept any character in any position. In StrictMode encoding mistakes will not be tolerated and QUrl will also check that certain forbidden characters are not present in unencoded form. If an error is detected in StrictMode isValid() will return false.

The parsing mode DecodedMode is not permitted when constructing a URL.

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.example.com/List%20of%20holidays.xml");
See also
setUrl(), setEncodedUrl(), fromEncoded(), QUrl::ParsingMode
QUrl::QUrl ( QUrl &&  other)
inline

Move constructs a new QUrl from other.

QUrl::~QUrl ( )

Destroys the QUrl.

Method Documentation

void QUrl::addEncodedQueryItem ( const QByteArray key,
const QByteArray value 
)
inlinedeprecated
Deprecated:

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

This method 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.

See also
addQueryItem()
void QUrl::addQueryItem ( const QString key,
const QString value 
)
inlinedeprecated
Deprecated:

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().

This method does not encode spaces (ASCII 0x20) as plus (+) signs, like HTML forms do. If you need that kind of encoding, you must encode the value yourself and use QUrl::addEncodedQueryItem.

See also
addEncodedQueryItem()
QUrl QUrl::adjusted ( QUrl::FormattingOptions  options) const
nodiscard

Returns an adjusted version of the URL. The output can be customized by passing flags with options. This is equivalent to QUrl(url.toString(options)).

See also
QUrl::FormattingOptions, toEncoded(), toString()
QList< QByteArray > QUrl::allEncodedQueryItemValues ( const QByteArray key) const
inlinedeprecated
Deprecated:

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

If the encoded key does not match the encoded version of the query this method will not work. For example, if the encoded query of this URL is "search=CopperSpice%20Rocks", calling this method with key = "%73earch" will return an empty string.

See also
allQueryItemValues(), queryItemValue(), encodedQueryItemValue()
QStringList QUrl::allQueryItemValues ( const QString key) const
inlinedeprecated
Deprecated:

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

This method does not decode spaces plus (+) signs as spaces (ASCII 0x20), like HTML forms do. If you need that kind of decoding, you must use QUrl::allEncodedQueryItemValues and decode the data yourself.

See also
queryItemValue()
QString QUrl::authority ( FormattingOptions  options = PrettyDecoded) const

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

The options argument controls how to format the user info component. The value of QUrl::FullyDecoded is not permitted in this method. If you need to obtain fully decoded data, call userName(), password(), host() and port() individually.

This method returns an unambiguous value which may contain characters still percent encoded. It may also contain some control sequences which are not representable in decoded form in a QString.

See also
setAuthority(), userInfo(), userName(), password(), host(), port()
void QUrl::clear ( )

Resets the content of the QUrl. After calling this method the current object is equal to constructing a default empty QUrl.

QByteArray QUrl::encodedFragment ( ) const
inlinedeprecated
Deprecated:

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().

See also
setEncodedFragment(), toEncoded()
QByteArray QUrl::encodedHost ( ) const
inlinedeprecated
Deprecated:

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

This methods 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 method is equivalent to calling QUrl::toAce() on the return value of host().

See also
setEncodedHost()
QByteArray QUrl::encodedPassword ( ) const
inlinedeprecated
Deprecated:

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().

See also
setEncodedPassword(), toEncoded()
QByteArray QUrl::encodedPath ( ) const
inlinedeprecated
Deprecated:

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().

See also
setEncodedPath(), toEncoded()
QByteArray QUrl::encodedQuery ( ) const
inlinedeprecated
Deprecated:

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

See also
setEncodedQuery()
QList< QPair< QByteArray, QByteArray > > QUrl::encodedQueryItems ( ) const
inlinedeprecated
Deprecated:

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

See also
setEncodedQueryItems(), setQueryItems(), setEncodedQuery()
QByteArray QUrl::encodedQueryItemValue ( const QByteArray key) const
inlinedeprecated
Deprecated:

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

If the encoded key does not match the encoded version of the query this method will not work. For example, if the encoded query of this URL is "search=CopperSpice%20Rocks", calling this method with key = "%73earch" will return an empty string.

See also
queryItemValue(), allQueryItemValues()
QByteArray QUrl::encodedUserName ( ) const
inlinedeprecated
Deprecated:

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().

See also
setEncodedUserName()
QString QUrl::errorString ( ) const

Returns a text string explaining why a URL is invalid. If there is no error it returns an empty string.

QString QUrl::fileName ( FormattingOptions  options = FullyDecoded) const

Returns the name of the file, excluding the directory path. If this QUrl object is given a path ending in a slash, the name of the file is considered empty. If the path does not contain a slash the entire path is considered the file name.

The options argument controls how to format the file name component. Using QUrl::FullyDecoded all percent encoded sequences are decoded. For other options the returned value may contain percent encoded sequences for control sequences, which are not representable in a QString.

QUrl url("https://www.copperspice.com/docs/cs_overview/index.html");
// url.adjusted(RemoveFilename) == "https://www.copperspice.com/docs/cs_overview/"
// url.fileName() == "index.html"
See also
path()
QString QUrl::fragment ( FormattingOptions  options = PrettyDecoded) const

Returns the fragment of the URL. To determine if the parsed URL contained a fragment use hasFragment().

The options argument controls how to format the fragment component. Using QUrl::FullyDecoded, all percent encoded sequences are decoded. For other options the returned value may contain percent encoded sequences for control sequences, which are not representable in a QString.

Using QUrl::FullyDecoded may cause data loss if those non-representable sequences are present. It is recommended to use this value when the result will be used in a non-URL context.

See also
setFragment(), hasFragment()
QString QUrl::fromAce ( const QByteArray domain)
static

Converts domain from ACE format to a QString.

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 to be written using non ASCII characters.

Returns the Unicode form of the given domain name domain, which is encoded in the ASCII Compatible Encoding (ACE).

If the value in domain can not be decoded it will be converted to a 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.

QString QUrl::fromAce ( const QString domain)
static

Returns the Unicode form of the given domain name domain, which is encoded in the ASCII Compatible Encoding (ACE).

If the value in domain can not be decoded it will be converted to a 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.

QUrl QUrl::fromCFURL ( CFURLRef  url)
static

Constructs a QUrl containing a copy of the CFURL url.

QUrl QUrl::fromEncoded ( const QByteArray url,
ParsingMode  mode = TolerantMode 
)
static

Parses url and returns the corresponding QUrl. The parameter input is assumed to be in an encoded form containing only ASCII characters. Parses the URL using mode.

Refer to setUrl() for more information on the ParsingMode parameter. QUrl::DecodedMode is not permitted as the ParsingMode for this method.

See also
toEncoded(), setUrl()
QUrl QUrl::fromLocalFile ( const QString localfile)
static

Returns a QUrl representation of localfile interpreted as a local file.

  • The localFile can contain a path separated by either slashes or the native separator of the target platform.
  • A path may also begin with a doubled leading slash or backslash to indicate a remote file, as in "//servername/path/to/file.txt". Only certain platforms can actually open this file using QFile::open().
  • Passing an empty localFile parameter results in an empty URL.

The following is an example of a valid absolute file URL.

qDebug() << QUrl::fromLocalFile("/home/user/file.txt"); // prints: "file:///home/user/file.txt"

A file URL with a relative path is only valid if a base URL is supplied. To resolve this type of URL first remove the URL scheme which is the part before the first colon.

QUrl url_relative = QUrl::fromLocalFile("file.txt");
QUrl url_base = QUrl("file:/home/user/");
url_relative.setScheme(QString());
qDebug() << url_base.resolved(url_relative); // prints: "file:///home/user/file.txt"

An easier approach is to construct a relative URL with no scheme.

QUrl url_relative = QUrl("file.txt");
QUrl url_base = QUrl("file:/home/user/");
qDebug() << url_base.resolved(url_relative); // prints: "file:///home/user/file.txt"
See also
toLocalFile(), isLocalFile(), QDir::toNativeSeparators()
QUrl QUrl::fromNSURL ( const NSURL *  url)
static

Constructs a QUrl containing a copy of the NSURL url.

QString QUrl::fromPercentEncoding ( const QByteArray input)
static

Converts input from percent encoding to a QString.

QString QUrl::fromPunycode ( const QByteArray punycode)
inlinedeprecatedstatic
Deprecated:

Returns the Punycode decoded representation of punycode.

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().

QList< QUrl > QUrl::fromStringList ( const QStringList urls,
ParsingMode  mode = TolerantMode 
)
static

Converts urls into a list of QUrl objects using the constructor QUrl(str, mode).

QUrl QUrl::fromUserInput ( const QString userInput)
static

Returns a valid URL from a user supplied userInput string. If the user input string corresponds to a valid file path on the system a "file://" URL is returned using QUrl::fromLocalFile(). If the user input string starts with "ftp" then "ftp://" is prepended to the URL. Otherwise "http://" is prepended to the URL.

If the input string can not be parsed, an invalid QUrl() is returned.

InputResult
www.copperspice.com https://www.copperspice.com
ftp.copperspice.com ftp://ftp.copperspice.com
hostname http://hostname
/home/user/test.html file:///home/user/test.html
QUrl QUrl::fromUserInput ( const QString userInput,
const QString workingDirectory,
UserInputResolutionOptions  options = DefaultResolution 
)
static

Returns a valid URL from a user supplied userInput string. If the input string can not be parsed, an invalid QUrl() is returned.

The workingDirectory path is used in order to be able to handle relative paths. This is especially useful when handling command line arguments. If the workingDirectory is empty no handling of relative paths will be done. By default, an input string that looks like a relative path will only be treated as such if the file actually exists in the given working directory. If the application can handle files that do not exist yet it should pass the flag AssumeLocalFile in options.

bool QUrl::hasEncodedQueryItem ( const QByteArray key) const
inlinedeprecated
Deprecated:

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

If the encoded key does not match the encoded version of the query this method will not work. For example, if the encoded query of this URL is "search=CopperSpice%20Rocks", calling this method with key = "%73earch" will return false.

See also
hasQueryItem()
bool QUrl::hasFragment ( ) const

Returns true if this URL contains a fragment. This means the path contains a # sign.

See also
fragment(), setFragment()
bool QUrl::hasQuery ( ) const

Returns true if this URL contains a Query. This means the path contains a ? symbol.

See also
hasQueryItem(), encodedQuery()
bool QUrl::hasQueryItem ( const QString key) const
inlinedeprecated
Deprecated:

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

See also
hasEncodedQueryItem()
QString QUrl::host ( FormattingOptions  options = FullyDecoded) const

Returns the host of the URL if it is defined, otherwise an empty string is returned. The options argument controls how the host name will be formatted.

The QUrl::EncodeUnicode option will cause this method to return the host name in the ASCII-Compatible Encoding (ACE) form, which is suitable for use in channels that are not 8-bit clean or that require the legacy hostname (such as DNS requests or in HTTP request headers). If that flag is not present the method returns the International Domain Name (IDN) in Unicode form according to the list of permissible top-level domains as returned from the idnWhitelist() methods.

All other flags are ignored. Host names can not contain control or percent characters so the returned value is always fully decoded.

See also
setHost(), idnWhitelist(), setIdnWhitelist(), authority()
QStringList QUrl::idnWhitelist ( )
static

Returns the current whitelist of top-level domains that are allowed to have non-ASCII characters in their compositions. Refer to setIdnWhitelist() for an explanation of this list.

bool QUrl::isEmpty ( ) const

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

bool QUrl::isLocalFile ( ) const

Returns true if this URL is pointing to a local file path. A URL is a local file path if the scheme is "file". This method considers URLs with host names to be a local file path, even if the eventual file path can not be opened with QFile::open().

See also
fromLocalFile(), toLocalFile()
bool QUrl::isParentOf ( const QUrl &  url) const

Returns true if this URL is a parent of url.

bool QUrl::isRelative ( ) const

Returns true if the URL is relative, otherwise returns false. A URL is relative if its scheme is undefined. Equivalent to calling scheme().isEmpty().

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").formatArg(url.toString()));
return false;
}
return true;
}
bool QUrl::matches ( const QUrl &  url,
FormattingOptions  options 
) const

Returns true if this URL and the given url are equal after both are formatted using the given options. Equivalent to calling QUrl:adjusted(options) on both URLs and then comparing the results.

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

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

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

Returns true if this URL is "less than" the given url.

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

Copy assigns from other and returns a reference to this object.

QUrl & QUrl::operator= ( QUrl &&  other)
inline

Move assigns from other and returns a reference to this object.

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

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

QString QUrl::password ( FormattingOptions  options = FullyDecoded) const

Returns the password of the URL if one exists, otherwise an empty string is returned.

See also
setPassword()
QString QUrl::path ( FormattingOptions  options = FullyDecoded) const

Returns the path of the URL.

See also
setPath()
int QUrl::port ( int  defaultPort = -1) const

Returns the port of the URL or defaultPort if the port is unspecified.

QTcpSocket socket;
socket.connectToHost(url.host(), url.port(80));
See also
setPort()
QString QUrl::query ( FormattingOptions  options = PrettyDecoded) const

Returns the query string of the URL if one exists otherwise an empty string is returned. To determine if the parsed URL contained a query string use hasQuery().

The options argument controls how to format the query component. Using QUrl::FullyDecoded all percent encoded sequences are decoded. For other options the return value may contain percent encoded sequences for control sequences which are not representable in a QString.

Using QUrl::FullyDecoded in queries is discouraged as queries often contain data which is supposed to remain percent encoded, including the use of the "%2B" sequence to represent a plus character.

See also
setQuery(), hasQuery()
QList< QPair< QString, QString > > QUrl::queryItems ( ) const
inlinedeprecated
Deprecated:

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

This method does not decode spaces plus (+) signs as spaces (ASCII 0x20), like HTML forms do. If you need that kind of decoding, you must use QUrl::encodedQueryItems and decode the data yourself.

See also
setQueryItems(), setEncodedQuery()
QString QUrl::queryItemValue ( const QString key) const
inlinedeprecated
Deprecated:

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

This method does not decode spaces plus (+) signs as spaces (ASCII 0x20), like HTML forms do. If you need that kind of decoding, you must use QUrl::encodedQueryItemValue and decode the data yourself.

See also
allQueryItemValues()
void QUrl::removeAllEncodedQueryItems ( const QByteArray key)
inlinedeprecated
Deprecated:

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

If the encoded key does not match the encoded version of the query this method will not work. For example, if the encoded query of this URL is "search=CopperSpice%20Rocks", calling this method with key = "%73earch" will do nothing.

See also
removeQueryItem()
void QUrl::removeAllQueryItems ( const QString key)
inlinedeprecated
Deprecated:

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

See also
removeQueryItem()
void QUrl::removeEncodedQueryItem ( const QByteArray key)
inlinedeprecated
Deprecated:

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

If the encoded key does not match the encoded version of the query this method will not work. For example, if the encoded query of this URL is "search=CopperSpice%20Rocks", calling this method with key = "%73earch" will do nothing.

See also
removeQueryItem(), removeAllQueryItems()
void QUrl::removeQueryItem ( const QString key)
inlinedeprecated
Deprecated:

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

See also
removeAllQueryItems()
QUrl QUrl::resolved ( const QUrl &  relative) const
nodiscard

Returns the result of combining this base URL with given relative URL. If relative is not a relative URL this method will return relative unchanged. Otherwise, the path of the two URLs are merged and the new URL is returned with the scheme and authority of the base URL and the merged path.

QUrl base_url("https://www.copperspice.com/");
QUrl relative_url("/docs/cs_api/index.html");
qDebug(base_url.resolved(relativeUrl).toString()); // prints "https://www.copperspice.com/docs/cs_api/index.html"

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()
QString QUrl::scheme ( ) const

Returns the scheme of the URL. If an empty string is returned this means no scheme exits so the URL is relative.

See also
setScheme(), isRelative()
void QUrl::setAuthority ( const QString authority,
ParsingMode  mode = TolerantMode 
)

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 so an empty authority is valid. The user info and host are separated by a "@", and the host and port are separated by a colon. If the user info is empty, the "@" must be omitted although a stray ":" is permitted if the port is empty.

See also
authority()
void QUrl::setEncodedFragment ( const QByteArray fragment)
inlinedeprecated
Deprecated:

Sets the fragment of the URL to the percent encoded fragment. The fragment is the last part of the URL represented by a "#" sign 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 empty fragment will remove the fragment in the URL. Passing an argument of QString("") will set the fragment to an empty string as if the original URL had ended with "#" sign.

See also
setFragment(), encodedFragment()
void QUrl::setEncodedHost ( const QByteArray host)
inlinedeprecated
Deprecated:

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().

See also
setHost(), encodedHost(), setAuthority(), fromAce()
void QUrl::setEncodedPassword ( const QByteArray password)
inlinedeprecated
Deprecated:

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().

This method does not verify that password is properly encoded. It is the caller's responsibility to ensure the delimiters, such as colons or slashes, are properly encoded.

See also
setPassword(), encodedPassword(), setUserInfo()
void QUrl::setEncodedPath ( const QByteArray path)
inlinedeprecated
Deprecated:

Sets the path of the URL 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.

See also
setPath(), encodedPath(), setUserInfo()
void QUrl::setEncodedQuery ( const QByteArray query)
inlinedeprecated
Deprecated:

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 method 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 unsets the query. 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()
void QUrl::setEncodedQueryItems ( const QList< QPair< QByteArray, QByteArray >> &  query)
inlinedeprecated
Deprecated:

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().

This method does not verify that the key-value pairs are properly encoded. It is the caller's responsibility to ensure the query delimiters are properly encoded.

See also
encodedQueryItems(), setQueryItems()
void QUrl::setEncodedUrl ( const QByteArray url,
ParsingMode  parsingMode = TolerantMode 
)
inlinedeprecated
Deprecated:

Constructs a QUrl by parsing the contents of url using the given parsingMode. This parameter is assumed to be a url string in percent encoded form containing only ASCII characters.

See also
setUrl()
void QUrl::setEncodedUserName ( const QByteArray userName)
inlinedeprecated
Deprecated:

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().

This method does not verify if the userName is properly encoded. It is the caller's responsibility to ensure the delimiters, such as colons or slashes are properly encoded.

See also
setUserName(), encodedUserName(), setUserInfo()
void QUrl::setFragment ( const QString fragment,
ParsingMode  mode = TolerantMode 
)

Sets the fragment of the URL to fragment. The fragment is the last part of the URL represented by a "#" sign 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 empty fragment will remove the fragment in the URL. Passing an argument of QString("") will set the fragment to an empty string as if the original URL had ended with "#" sign.

See also
fragment(), hasFragment()
void QUrl::setHost ( const QString host,
ParsingMode  mode = DecodedMode 
)

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

See also
host(), setAuthority()
void QUrl::setIdnWhitelist ( const QStringList list)
static

Sets the IDN whitelist to list. The IDN whitelist indicates which Top-Level Domains (TLDs) permit non ASCII characters.

CopperSpice contains a list of the Internet top-level domains which support Internationalized Domain Names (IDNs). There are rules to guarantee domains which "look the same" will not be registered. The definition of "look the same" is based on characters in Unicode look similar in most fonts. Since the Unicode code points in the following example are different, this could result in a two different domain names which look identical to the user but resolve to different web sites.

  • Latin letter "a", code point U+0061
  • Cyrillic letter "a" (used in Russian), code point U+0430

The following are examples of other characters which are difficult to distinguish.

  • Cyrillic З, Ч and б resemble the numerals 3, 4 and 6
  • Greek beta β can be a substitute for German esszet ß in some fonts
  • Greek sigma ς for French ç
  • Hebrew heth (ח) which resembles the Latin letter n.

This method is provided for those who need to manipulate the list in order to add or remove a TLD. However, it is not recommended to alter this list other than for testing as it may expose users to security risks.

If you call this method do so before you start any threads that might access idnWhitelist().

See also
idnWhitelist()
void QUrl::setPassword ( const QString password,
ParsingMode  mode = DecodedMode 
)

Sets the URL 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()
void QUrl::setPath ( const QString path,
ParsingMode  mode = DecodedMode 
)

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()
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(). The parameter for port must be between 0 and 65535 inclusive. Setting the port to -1 indicates that the port is unspecified.

See also
port()
void QUrl::setQuery ( const QString query,
ParsingMode  mode = TolerantMode 
)

Sets the query string of the URL to query. Passing a value of QString() to query unsets the query. Passing a value of QString("") will set the query to an empty value as if the original URL had ended with a "?" symbol.

This method 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.

The query data is interpreted based on mode. In StrictMode any "%" character must be followed by exactly two hexadecimal characters. Some characters (including space) are not allowed in undecoded form. In TolerantMode all characters are accepted in undecoded form and the tolerant parser will correct a stray "%" not followed by two hex characters. In DecodedMode a "%" character will always be interpreted as a literal percent character.

Query strings often contain percent encoded sequences, so use of DecodedMode is discouraged. One special sequence to be aware of is that of the plus character. QUrl does not convert spaces to plus characters, even though HTML forms posted by web browsers do. In order to represent an actual plus character in a query, the sequence "%2B" is usually used. This function will leave "%2B" sequences untouched in TolerantMode or StrictMode.

See also
query(), hasQuery()
void QUrl::setQuery ( const QUrlQuery query)

Sets the query string of the URL to query. This method reconstructs the query string from the QUrlQuery object.

See also
query(), hasQuery()
void QUrl::setQueryItems ( const QList< QPair< QString, QString >> &  query)
inlinedeprecated
Deprecated:

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().

This method does not encode spaces (ASCII 0x20) as plus (+) signs, like HTML forms do. If you need this kind of encoding you must encode the value yourself and use QUrl::setEncodedQueryItems.

See also
queryItems(), setEncodedQueryItems()
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 can also be empty in which case the URL is interpreted as relative.

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

See also
scheme(), isRelative()
void QUrl::setUrl ( const QString url,
ParsingMode  mode = TolerantMode 
)

Parses the url using the parser given mode.

In TolerantMode QUrl will correct certain mistakes, notably the presence of a percent character not followed by two hexadecimal digits, and it will accept any character in any position. In StrictMode, encoding mistakes will not be tolerated and QUrl will also check that certain forbidden characters are not present in unencoded form. If an error is detected in StrictMode isValid() will return false. The parsing mode DecodedMode is not permitted in this context and will produce a runtime warning.

QUrl will automatically percent encode all characters that are not allowed in a URL and decode the percent encoded sequences that represent an unreserved character (letters, digits, hyphens, underscores, dots and tildes). All other characters are left in their original forms.

See also
url(), toString()
void QUrl::setUserInfo ( const QString userInfo,
ParsingMode  mode = TolerantMode 
)

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 colon. If the password is empty the colon must be omitted. The following example shows a valid user info string:

See also
userInfo(), setUserName(), setPassword(), setAuthority()
void QUrl::setUserName ( const QString userName,
ParsingMode  mode = DecodedMode 
)

Sets the URL 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
setEncodedUserName(), userName(), setUserInfo()
void QUrl::swap ( QUrl &  other)
inline

Swaps other with this object. This operation is very fast and never fails.

QByteArray QUrl::toAce ( const QString domain)
static

Converts the domain from a QString to and ACE encoded QByteArray. This method returns an empty QByteArray if the domain is not a valid host name.

IPv6 literals are not valid domain names.

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 to be written using non ASCII characters.

CFURLRef QUrl::toCFURL ( ) const

Creates a CFURL from a QUrl. The caller owns the CFURL and is responsible for releasing it.

QString QUrl::toDisplayString ( QUrl::FormattingOptions  options = FormattingOptions(PrettyDecoded)) const

Returns a human-displayable string representation of the URL. The output can be customized by passing flags with options. The option RemovePassword is always enabled, since passwords should never be shown back to users.

With the default options, the resulting QString can be passed back to a QUrl later on, but any password that was present initially will be lost.

See also
toEncoded(), toString()
QByteArray QUrl::toEncoded ( QUrl::FormattingOptions  options = FullyEncoded) const

Returns the encoded representation of the URL if it is 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. All non-ASCII characters are then percent encoded. The host name is encoded using Punycode.

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 is a relative URL this method will return the path.

If this URL contains a non-empty host name, it will be encoded in the returned value in the form found on SMB networks. For example, "//servername/path/to/file.txt".

See also
fromLocalFile(), isLocalFile()
NSURL * QUrl::toNSURL ( ) const

Creates a NSURL from a QUrl. The NSURL is autoreleased.

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

Returns an encoded copy of input which 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}"
QString QUrl::topLevelDomain ( FormattingOptions  options = FullyDecoded) const

Returns the TLD (Top-Level Domain) of the URL. The return value is prefixed with a period unless the URL does not contain a valid TLD, in which case the method returns an empty string.

QByteArray QUrl::toPunycode ( const QString string)
inlinedeprecatedstatic
Deprecated:

Returns string 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().

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

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

See also
toEncoded()
QStringList QUrl::toStringList ( const QList< QUrl > &  urls,
QUrl::FormattingOptions  options = FormattingOptions(PrettyDecoded) 
)
static

Converts a list of urls into a list of QString objects, using toString(options).

QString QUrl::url ( FormattingOptions  options = FormattingOptions(PrettyDecoded)) const

Returns a string representation of the URL. The output can be customized by passing flags with options. The option QUrl::FullyDecoded is not permitted in this method since it would generate ambiguous data. The returned result can be passed back to a QUrl.

Equivalent to calling toString(options).

See also
toEncoded(), toString()
QString QUrl::userInfo ( FormattingOptions  options = PrettyDecoded) const

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

See also
setUserInfo()
QString QUrl::userName ( FormattingOptions  options = FullyDecoded) const

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

See also
setUserName(), encodedUserName()

Friends And Related Function Documentation

QDataStream & operator<< ( QDataStream stream,
const QUrl &  url 
)
related

Writes the given url to the stream. Returns a reference to the stream.

Refer to Serializing Data Types for additional information.

QDataStream & operator>> ( QDataStream steam,
QUrl &  url 
)
related

Reads from the stream into the given url. Returns a reference to the stream.

Refer to Serializing Data Types for additional information.

uint qHash ( const QUrl &  url,
uint  seed = 0 
)
related

Returns the hash value for url using seed to seed the calculation.