Qt 4.8
Public Types | Public Functions | Static Public Functions | Private Functions | Properties | Related Functions | List of all members
QUrl Class Reference

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

#include <qurl.h>

Public Types

typedef QUrlPrivateDataPtr
 
enum  FormattingOption {
  None = 0x0, RemoveScheme = 0x1, RemovePassword = 0x2, RemoveUserInfo = RemovePassword | 0x4,
  RemovePort = 0x8, RemoveAuthority = RemoveUserInfo | RemovePort | 0x10, RemovePath = 0x20, RemoveQuery = 0x40,
  RemoveFragment = 0x80, StripTrailingSlash = 0x10000
}
 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< QByteArrayallEncodedQueryItemValues (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...
 
DataPtrdata_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...
 
QUrloperator= (const QUrl &copy)
 Assigns the specified url to this object. More...
 
QUrloperator= (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 &copy)
 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

QUrlPrivated
 

Related Functions

(Note that these are not member functions.)

QDataStreamoperator<< (QDataStream &out, const QUrl &url)
 Writes url url to the stream out and returns a reference to the stream. More...
 
QDataStreamoperator>> (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)
 

Detailed Description

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

Note
This class or function is reentrant.

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

Character Conversions

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

See also
QUrlInfo

Definition at line 61 of file qurl.h.

Typedefs

◆ DataPtr

Warning
This function is not part of the public interface.

Definition at line 281 of file qurl.h.

Enumerations

◆ FormattingOption

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

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

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 

Definition at line 70 of file qurl.h.

70  {
71  None = 0x0,
72  RemoveScheme = 0x1,
73  RemovePassword = 0x2,
75  RemovePort = 0x8,
77  RemovePath = 0x20,
78  RemoveQuery = 0x40,
79  RemoveFragment = 0x80,
80  // 0x100: private: normalized
81 
82  StripTrailingSlash = 0x10000
83  };

◆ ParsingMode

The parsing mode controls the way QUrl parses strings.

  • TolerantMode QUrl will try to correct some common errors in URLs. This mode is useful when processing URLs entered by users.
  • StrictMode Only valid URLs are accepted. This mode is useful for general URL validation.

In TolerantMode, the parser corrects the following invalid input:

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

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

  • 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 

Definition at line 64 of file qurl.h.

64  {
67  };

Constructors and Destructors

◆ QUrl() [1/4]

QUrl::QUrl ( )

Constructs an empty QUrl object.

Definition at line 4272 of file qurl.cpp.

Referenced by fromUserInput().

4272  : d(0)
4273 {
4274 }
QUrlPrivate * d
Definition: qurl.h:279

◆ QUrl() [2/4]

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:

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://qt.nokia.com/List%20of%20holidays.xml");
See also
setUrl(), setEncodedUrl(), fromEncoded(), TolerantMode

Definition at line 4242 of file qurl.cpp.

4242  : d(0)
4243 {
4244  if (!url.isEmpty())
4245  setUrl(url);
4246 }
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void setUrl(const QString &url)
Constructs a URL by parsing the contents of url.
Definition: qurl.cpp:4358
QUrlPrivate * d
Definition: qurl.h:279

◆ QUrl() [3/4]

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.

See also
setUrl()

Definition at line 4259 of file qurl.cpp.

4259  : d(0)
4260 {
4261  if (!url.isEmpty())
4262  setUrl(url, parsingMode);
4263  else {
4264  d = new QUrlPrivate;
4265  d->parsingMode = parsingMode;
4266  }
4267 }
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QUrl::ParsingMode parsingMode
Definition: qurl.cpp:371
void setUrl(const QString &url)
Constructs a URL by parsing the contents of url.
Definition: qurl.cpp:4358
QUrlPrivate * d
Definition: qurl.h:279

◆ QUrl() [4/4]

QUrl::QUrl ( const QUrl copy)

Constructs a copy of other.

Definition at line 4279 of file qurl.cpp.

4279  : d(other.d)
4280 {
4281  if (d)
4282  d->ref.ref();
4283 }
bool ref()
Atomically increments the value of this QAtomicInt.
QAtomicInt ref
Definition: qurl.cpp:354
QUrlPrivate * d
Definition: qurl.h:279

◆ ~QUrl()

QUrl::~QUrl ( )

Destructor; called immediately before the object is deleted.

Definition at line 4288 of file qurl.cpp.

4289 {
4290  if (d && !d->ref.deref())
4291  delete d;
4292 }
QAtomicInt ref
Definition: qurl.cpp:354
bool deref()
Atomically decrements the value of this QAtomicInt.
QUrlPrivate * d
Definition: qurl.h:279

Functions

◆ addEncodedQueryItem()

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

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

Since
4.4

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.

See also
addQueryItem(), setQueryDelimiters()

Definition at line 5279 of file qurl.cpp.

5280 {
5281  if (!d) d = new QUrlPrivate;
5282  QMutexLocker lock(&d->mutex);
5284  detach(lock);
5285 
5286  if (!d->query.isEmpty())
5287  d->query += d->pairDelimiter;
5288 
5289  d->query += key;
5290  d->query += d->valueDelimiter;
5291  d->query += value;
5292 
5293  d->hasQuery = !d->query.isEmpty();
5294 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
void detach()
Forces a detach.
Definition: qurl.cpp:6313
QByteArray query
Definition: qurl.cpp:361
QUrlPrivate * d
Definition: qurl.h:279
bool hasQuery
Definition: qurl.cpp:373
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
char valueDelimiter
Definition: qurl.cpp:378
char pairDelimiter
Definition: qurl.cpp:379

◆ addQueryItem()

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

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

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

Definition at line 5240 of file qurl.cpp.

5241 {
5242  if (!d) d = new QUrlPrivate;
5243  QMutexLocker lock(&d->mutex);
5245  detach(lock);
5246 
5247  char alsoEncode[3];
5248  alsoEncode[0] = d->valueDelimiter;
5249  alsoEncode[1] = d->pairDelimiter;
5250  alsoEncode[2] = 0;
5251 
5252  if (!d->query.isEmpty())
5253  d->query += d->pairDelimiter;
5254 
5255  // query = *( pchar / "/" / "?" )
5256  d->query += toPercentEncodingHelper(key, queryExcludeChars, alsoEncode);
5257  d->query += d->valueDelimiter;
5258  // query = *( pchar / "/" / "?" )
5259  d->query += toPercentEncodingHelper(value, queryExcludeChars, alsoEncode);
5260 
5261  d->hasQuery = !d->query.isEmpty();
5262 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
static QByteArray toPercentEncodingHelper(const QString &s, const char *exclude, const char *include=0)
Definition: qurl.cpp:233
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
void detach()
Forces a detach.
Definition: qurl.cpp:6313
static const char queryExcludeChars[]
Definition: qurl.cpp:3547
QByteArray query
Definition: qurl.cpp:361
QUrlPrivate * d
Definition: qurl.h:279
bool hasQuery
Definition: qurl.cpp:373
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
char valueDelimiter
Definition: qurl.cpp:378
char pairDelimiter
Definition: qurl.cpp:379

◆ allEncodedQueryItemValues()

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.

Since
4.4

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.

See also
allQueryItemValues(), queryItemValue(), encodedQueryItemValue()

Definition at line 5516 of file qurl.cpp.

5517 {
5518  if (!d) return QList<QByteArray>();
5519  QMutexLocker lock(&d->mutex);
5521 
5523 
5524  int pos = 0;
5525  const char *query = d->query.constData();
5526  while (pos < d->query.size()) {
5527  int valuedelim, end;
5528  d->queryItem(pos, &valuedelim, &end);
5529  if (key == QByteArray::fromRawData(query + pos, valuedelim - pos))
5530  values += valuedelim < end ?
5531  QByteArray(query + valuedelim + 1, end - valuedelim - 1)
5532  : QByteArray();
5533  pos = end + 1;
5534  }
5535 
5536  return values;
5537 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
static QByteArray fromRawData(const char *, int size)
Constructs a QByteArray that uses the first size bytes of the data array.
void queryItem(int pos, int *value, int *end)
Definition: qurl.cpp:3727
QByteArray query
Definition: qurl.cpp:361
quint16 values[128]
QUrlPrivate * d
Definition: qurl.h:279
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
static const KeyPair *const end

◆ allQueryItemValues()

QStringList QUrl::allQueryItemValues ( const QString key) const

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

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

Definition at line 5474 of file qurl.cpp.

5475 {
5476  if (!d) return QStringList();
5477  QMutexLocker lock(&d->mutex);
5479 
5480  QByteArray encodedKey = toPercentEncoding(key, queryExcludeChars);
5482 
5483  int pos = 0;
5484  const char *query = d->query.constData();
5485  while (pos < d->query.size()) {
5486  int valuedelim, end;
5487  d->queryItem(pos, &valuedelim, &end);
5488  if (encodedKey == QByteArray::fromRawData(query + pos, valuedelim - pos)) {
5489  QByteArray v(query + valuedelim + 1, end - valuedelim - 1);
5490  values += valuedelim < end ?
5492  : QString();
5493  }
5494  pos = end + 1;
5495  }
5496 
5497  return values;
5498 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
static QByteArray toPercentEncoding(const QString &, const QByteArray &exclude=QByteArray(), const QByteArray &include=QByteArray())
Returns an encoded copy of input.
Definition: qurl.cpp:6009
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
The QString class provides a Unicode character string.
Definition: qstring.h:83
int stateFlags
Definition: qurl.cpp:387
static QString fromPercentEncodingMutable(QByteArray *ba)
Definition: qurl.cpp:251
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static QByteArray fromRawData(const char *, int size)
Constructs a QByteArray that uses the first size bytes of the data array.
static const char queryExcludeChars[]
Definition: qurl.cpp:3547
void queryItem(int pos, int *value, int *end)
Definition: qurl.cpp:3727
QByteArray query
Definition: qurl.cpp:361
quint16 values[128]
QUrlPrivate * d
Definition: qurl.h:279
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
static const KeyPair *const end

◆ authority()

QString QUrl::authority ( ) const

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

See also
setAuthority()

Definition at line 4592 of file qurl.cpp.

Referenced by QNetworkAccessFileBackendFactory::create(), isParentOf(), and QDeclarativeEnginePrivate::urlToLocalFileOrQrc().

4593 {
4594  if (!d) return QString();
4595 
4596  QMutexLocker lock(&d->mutex);
4598 
4599  return d->authority();
4600 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
The QString class provides a Unicode character string.
Definition: qstring.h:83
int stateFlags
Definition: qurl.cpp:387
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
QString authority(QUrl::FormattingOptions options=QUrl::None) const
Definition: qurl.cpp:3568

◆ clear()

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

4341 {
4342  if (d && !d->ref.deref())
4343  delete d;
4344  d = 0;
4345 }
QAtomicInt ref
Definition: qurl.cpp:354
bool deref()
Atomically decrements the value of this QAtomicInt.
QUrlPrivate * d
Definition: qurl.h:279

◆ data_ptr()

DataPtr & QUrl::data_ptr ( )
inline
Warning
This function is not part of the public interface.

Definition at line 282 of file qurl.h.

282 { return d; }
QUrlPrivate * d
Definition: qurl.h:279

◆ detach() [1/2]

void QUrl::detach ( )

Forces a detach.

Warning
This function is not part of the public interface.

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

6314 {
6315  if (!d) {
6316  d = new QUrlPrivate;
6317  } else {
6318  // Public method, so it must lock first.
6319  QMutexLocker lock(&d->mutex);
6320  detach(lock);
6321  }
6322 }
void detach()
Forces a detach.
Definition: qurl.cpp:6313
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394

◆ detach() [2/2]

void QUrl::detach ( QMutexLocker locker)
private

Forces a detach.

Warning
This function is not part of the public interface.

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.

6337 {
6338  Q_ASSERT(d); // we have a locker, so we have a d pointer
6339  // Ensure that we hold the mutex until after making our private copy,
6340  // so that another thread cannot deref + delete d meanwhile.
6341  // So this is a modified version of qAtomicDetach(d)
6342  if (d->ref == 1) {
6343  locker.unlock();
6344  return;
6345  }
6346  QUrlPrivate * x = d;
6347  d = new QUrlPrivate(*x);
6348  locker.unlock();
6349  if (!x->ref.deref())
6350  delete x;
6351 }
void unlock()
Unlocks this mutex locker.
Definition: qmutex.h:117
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QAtomicInt ref
Definition: qurl.cpp:354
bool deref()
Atomically decrements the value of this QAtomicInt.
QUrlPrivate * d
Definition: qurl.h:279

◆ encodedFragment()

QByteArray QUrl::encodedFragment ( ) const

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

Since
4.4

The returned value will have its non-ASCII and other control characters percent-encoded, as in toEncoded().

See also
setEncodedFragment(), toEncoded()

Definition at line 5753 of file qurl.cpp.

Referenced by QUrlPrivate::fragmentImpl().

5754 {
5755  if (!d) return QByteArray();
5756  QMutexLocker lock(&d->mutex);
5758 
5759  d->ensureEncodedParts();
5760  return d->encodedFragment;
5761 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
QByteArray encodedFragment
Definition: qurl.cpp:368
void ensureEncodedParts() const
Definition: qurl.cpp:3550

◆ encodedHost()

QByteArray QUrl::encodedHost ( ) const

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

Since
4.4

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

See also
setEncodedHost()

Definition at line 4884 of file qurl.cpp.

4885 {
4886  // should we cache this in d->encodedHost?
4887  return QUrl::toAce(host());
4888 }
QString host() const
Returns the host of the URL if it is defined; otherwise an empty string is returned.
Definition: qurl.cpp:4837
static QByteArray toAce(const QString &)
Returns the ASCII Compatible Encoding of the given domain name domain.
Definition: qurl.cpp:6158

◆ encodedPassword()

QByteArray QUrl::encodedPassword ( ) const

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

Since
4.4

The returned value will have its non-ASCII and other control characters percent-encoded, as in toEncoded().

See also
setEncodedPassword(), toEncoded()

Definition at line 4805 of file qurl.cpp.

4806 {
4807  if (!d) return QByteArray();
4808  QMutexLocker lock(&d->mutex);
4810 
4811  d->ensureEncodedParts();
4812  return d->encodedPassword;
4813 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
QByteArray encodedPassword
Definition: qurl.cpp:366
int stateFlags
Definition: qurl.cpp:387
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
void ensureEncodedParts() const
Definition: qurl.cpp:3550

◆ encodedPath()

QByteArray QUrl::encodedPath ( ) const

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

Since
4.4

The returned value will have its non-ASCII and other control characters percent-encoded, as in toEncoded().

See also
setEncodedPath(), toEncoded()

Definition at line 5038 of file qurl.cpp.

5039 {
5040  if (!d) return QByteArray();
5041  QMutexLocker lock(&d->mutex);
5043 
5044  d->ensureEncodedParts();
5045  return d->encodedPath;
5046 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
QByteArray encodedPath
Definition: qurl.cpp:367
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
void ensureEncodedParts() const
Definition: qurl.cpp:3550

◆ encodedQuery()

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

5644 {
5645  if (!d) return QByteArray();
5646  QMutexLocker lock(&d->mutex);
5648 
5649  return d->query;
5650 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
QByteArray query
Definition: qurl.cpp:361
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394

◆ encodedQueryItems()

QList< QPair< QByteArray, QByteArray > > QUrl::encodedQueryItems ( ) const

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

Since
4.4
See also
setEncodedQueryItems(), setQueryItems(), setEncodedQuery()

Definition at line 5342 of file qurl.cpp.

5343 {
5344  if (!d) return QList<QPair<QByteArray, QByteArray> >();
5345  QMutexLocker lock(&d->mutex);
5347 
5349 
5350  int pos = 0;
5351  const char *query = d->query.constData();
5352  while (pos < d->query.size()) {
5353  int valuedelim, end;
5354  d->queryItem(pos, &valuedelim, &end);
5355  if (valuedelim < end)
5356  itemMap += qMakePair(QByteArray(query + pos, valuedelim - pos),
5357  QByteArray(query + valuedelim + 1, end - valuedelim - 1));
5358  else
5359  itemMap += qMakePair(QByteArray(query + pos, valuedelim - pos), QByteArray());
5360  pos = end + 1;
5361  }
5362 
5363  return itemMap;
5364 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
void queryItem(int pos, int *value, int *end)
Definition: qurl.cpp:3727
QByteArray query
Definition: qurl.cpp:361
QUrlPrivate * d
Definition: qurl.h:279
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
static const KeyPair *const end
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ encodedQueryItemValue()

QByteArray QUrl::encodedQueryItemValue ( const QByteArray key) const

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

Since
4.4

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.

See also
queryItemValue(), allQueryItemValues()

Definition at line 5445 of file qurl.cpp.

Referenced by queryItemValue().

5446 {
5447  if (!d) return QByteArray();
5448  QMutexLocker lock(&d->mutex);
5450 
5451  int pos = 0;
5452  const char *query = d->query.constData();
5453  while (pos < d->query.size()) {
5454  int valuedelim, end;
5455  d->queryItem(pos, &valuedelim, &end);
5456  if (key == QByteArray::fromRawData(query + pos, valuedelim - pos))
5457  return valuedelim < end ?
5458  QByteArray(query + valuedelim + 1, end - valuedelim - 1) : QByteArray();
5459  pos = end + 1;
5460  }
5461  return QByteArray();
5462 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
static QByteArray fromRawData(const char *, int size)
Constructs a QByteArray that uses the first size bytes of the data array.
void queryItem(int pos, int *value, int *end)
Definition: qurl.cpp:3727
QByteArray query
Definition: qurl.cpp:361
QUrlPrivate * d
Definition: qurl.h:279
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
static const KeyPair *const end

◆ encodedUserName()

QByteArray QUrl::encodedUserName ( ) const

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

Since
4.4

The returned value will have its non-ASCII and other control characters percent-encoded, as in toEncoded().

See also
setEncodedUserName()

Definition at line 4719 of file qurl.cpp.

4720 {
4721  if (!d) return QByteArray();
4722  QMutexLocker lock(&d->mutex);
4724 
4725  d->ensureEncodedParts();
4726  return d->encodedUserName;
4727 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
QByteArray encodedUserName
Definition: qurl.cpp:365
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
void ensureEncodedParts() const
Definition: qurl.cpp:3550

◆ errorString()

QString QUrl::errorString ( ) const

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

Since
4.2

Definition at line 6800 of file qurl.cpp.

6801 {
6802  if (!d)
6803  return QLatin1String(QT_TRANSLATE_NOOP(QUrl, "Invalid URL \"\": ")); // XXX not a good message, but the one an empty URL produces
6804  QMutexLocker lock(&d->mutex);
6805  return d->createErrorString();
6806 }
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
QString createErrorString()
Definition: qurl.cpp:4164
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394

◆ fragment()

QString QUrl::fragment ( ) const

Returns the fragment of the URL.

See also
setFragment()

Definition at line 5687 of file qurl.cpp.

Referenced by QPatternist::ReportContext::codeFromURI(), QUrlPrivate::fragmentImpl(), QPatternist::ColoringMessageHandler::handleMessage(), setEncodedFragment(), setFragment(), and QTextBrowserPrivate::setSource().

5688 {
5689  if (!d) return QString();
5690  QMutexLocker lock(&d->mutex);
5692 
5693  return d->fragmentImpl();
5694 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString fragmentImpl() const
Definition: qurl.cpp:5696
int stateFlags
Definition: qurl.cpp:387
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394

◆ fromAce()

QString QUrl::fromAce ( const QByteArray domain)
static

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

Since
4.2

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

6135 {
6136  return qt_ACE_do(QString::fromLatin1(domain), NormalizeAce);
6137 }
static QString qt_ACE_do(const QString &domain, AceOperation op)
Definition: qurl.cpp:3334
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188

◆ fromEncoded() [1/2]

QUrl QUrl::fromEncoded ( const QByteArray input)
static

Parses input and returns the corresponding QUrl.

input is assumed to be in encoded form, containing only ASCII characters.

The URL is parsed using TolerantMode.

See also
toEncoded(), setUrl()

Definition at line 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().

5965 {
5966  QUrl tmp;
5967  tmp.setEncodedUrl(input, TolerantMode);
5968  return tmp;
5969 }
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
void setEncodedUrl(const QByteArray &url)
Constructs a URL by parsing the contents of encodedUrl.
Definition: qurl.cpp:4429

◆ fromEncoded() [2/2]

QUrl QUrl::fromEncoded ( const QByteArray input,
ParsingMode  parsingMode 
)
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.

See also
toEncoded(), setUrl()

Definition at line 5981 of file qurl.cpp.

5982 {
5983  QUrl tmp;
5984  tmp.setEncodedUrl(input, parsingMode);
5985  return tmp;
5986 }
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
void setEncodedUrl(const QByteArray &url)
Constructs a URL by parsing the contents of encodedUrl.
Definition: qurl.cpp:4429

◆ fromLocalFile()

QUrl QUrl::fromLocalFile ( const QString localFile)
static

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

See also
toLocalFile(), isLocalFile(), QDir::toNativeSeparators()

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

6375 {
6376  QUrl url;
6377  url.setScheme(QLatin1String("file"));
6378  QString deslashified = QDir::fromNativeSeparators(localFile);
6379 
6380  // magic for drives on windows
6381  if (deslashified.length() > 1 && deslashified.at(1) == QLatin1Char(':') && deslashified.at(0) != QLatin1Char('/')) {
6382  url.setPath(QLatin1Char('/') + deslashified);
6383  // magic for shared drive on windows
6384  } else if (deslashified.startsWith(QLatin1String("//"))) {
6385  int indexOfPath = deslashified.indexOf(QLatin1Char('/'), 2);
6386  url.setHost(deslashified.mid(2, indexOfPath - 2));
6387  if (indexOfPath > 2)
6388  url.setPath(deslashified.right(deslashified.length() - indexOfPath));
6389  } else {
6390  url.setPath(deslashified);
6391  }
6392 
6393  return url;
6394 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
void setPath(const QString &path)
Sets the path of the URL to path.
Definition: qurl.cpp:4960
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
void setHost(const QString &host)
Sets the host of the URL to host.
Definition: qurl.cpp:4821
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QString right(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n rightmost characters of the string.
Definition: qstring.cpp:3682
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
void setScheme(const QString &scheme)
Sets the scheme of the URL to scheme.
Definition: qurl.cpp:4533
static QString fromNativeSeparators(const QString &pathName)
Returns pathName using &#39;/&#39; as file separator.
Definition: qdir.cpp:848
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ fromPercentEncoding()

QString QUrl::fromPercentEncoding ( const QByteArray input)
static

Returns a decoded copy of input.

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

Definition at line 5992 of file qurl.cpp.

Referenced by QNetworkCookiePrivate::parseSetCookieHeaderLine(), swap(), and toString().

5993 {
5994  return fromPercentEncodingHelper(input);
5995 }
static QString fromPercentEncodingHelper(const QByteArray &ba)
Definition: qurl.cpp:242

◆ fromPunycode()

QString QUrl::fromPunycode ( const QByteArray pc)
static

Returns the Punycode decoded representation of pc.

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

Definition at line 6044 of file qurl.cpp.

Referenced by qt_ACE_do().

6045 {
6046  uint n = initial_n;
6047  uint i = 0;
6048  uint bias = initial_bias;
6049 
6050  // strip any ACE prefix
6051  int start = pc.startsWith("xn--") ? 4 : 0;
6052  if (!start)
6053  return QString::fromLatin1(pc);
6054 
6055  // find the last delimiter character '-' in the input array. copy
6056  // all data before this delimiter directly to the output array.
6057  int delimiterPos = pc.lastIndexOf(0x2d);
6058  QString output = delimiterPos < 4 ?
6059  QString() : QString::fromLatin1(pc.constData() + start, delimiterPos - start);
6060 
6061  // if a delimiter was found, skip to the position after it;
6062  // otherwise start at the front of the input string. everything
6063  // before the delimiter is assumed to be basic code points.
6064  uint cnt = delimiterPos + 1;
6065 
6066  // loop through the rest of the input string, inserting non-basic
6067  // characters into output as we go.
6068  while (cnt < (uint) pc.size()) {
6069  uint oldi = i;
6070  uint w = 1;
6071 
6072  // find the next index for inserting a non-basic character.
6073  for (uint k = base; cnt < (uint) pc.size(); k += base) {
6074  // grab a character from the punycode input and find its
6075  // delta digit (each digit code is part of the
6076  // variable-length integer delta)
6077  uint digit = pc.at(cnt++);
6078  if (digit - 48 < 10) digit -= 22;
6079  else if (digit - 65 < 26) digit -= 65;
6080  else if (digit - 97 < 26) digit -= 97;
6081  else digit = base;
6082 
6083  // reject out of range digits
6084  if (digit >= base || digit > (Q_MAXINT - i) / w)
6085  return QLatin1String("");
6086 
6087  i += (digit * w);
6088 
6089  // detect threshold to stop reading delta digits
6090  uint t;
6091  if (k <= bias) t = tmin;
6092  else if (k >= bias + tmax) t = tmax;
6093  else t = k - bias;
6094  if (digit < t) break;
6095 
6096  w *= (base - t);
6097  }
6098 
6099  // find new bias and calculate the next non-basic code
6100  // character.
6101  bias = adapt(i - oldi, output.length() + 1, oldi == 0);
6102  n += i / (output.length() + 1);
6103 
6104  // allow the deltas to wrap around
6105  i %= (output.length() + 1);
6106 
6107  // insert the character n at position i
6108  output.insert((uint) i, QChar((ushort) n));
6109  ++i;
6110  }
6111 
6112  return output;
6113 }
#define Q_MAXINT
Definition: qurl.cpp:267
static const uint initial_n
Definition: qurl.cpp:274
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static const uint tmin
Definition: qurl.cpp:269
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool startsWith(const QByteArray &a) const
Returns true if this byte array starts with byte array ba; otherwise returns false.
static const uint base
Definition: qurl.cpp:268
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
int lastIndexOf(char c, int from=-1) const
Returns the index position of the last occurrence of character ch in the byte array, searching backward from index position from.
static const uint tmax
Definition: qurl.cpp:270
unsigned int uint
Definition: qglobal.h:996
unsigned short ushort
Definition: qglobal.h:995
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
static uint adapt(uint delta, uint numpoints, bool firsttime)
Definition: qurl.cpp:3104
static const uint initial_bias
Definition: qurl.cpp:273
char at(int i) const
Returns the character at index position i in the byte array.
Definition: qbytearray.h:413
QString & insert(int i, QChar c)
Definition: qstring.cpp:1671

◆ fromUserInput()

QUrl QUrl::fromUserInput ( const QString userInput)
static

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.

Since
4.6

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

:

Examples:

Definition at line 6878 of file qurl.cpp.

6879 {
6880  QString trimmedString = userInput.trimmed();
6881 
6882  // Check first for files, since on Windows drive letters can be interpretted as schemes
6883  if (QDir::isAbsolutePath(trimmedString))
6884  return QUrl::fromLocalFile(trimmedString);
6885 
6886  QUrl url = QUrl::fromEncoded(trimmedString.toUtf8(), QUrl::TolerantMode);
6887  QUrl urlPrepended = QUrl::fromEncoded("http://" + trimmedString.toUtf8(), QUrl::TolerantMode);
6888 
6889  // Check the most common case of a valid url with a scheme
6890  // We check if the port would be valid by adding the scheme to handle the case host:port
6891  // where the host would be interpretted as the scheme
6892  if (url.isValid()
6893  && !url.scheme().isEmpty()
6894  && urlPrepended.port() == -1)
6895  return url;
6896 
6897  // Else, try the prepended one and adjust the scheme from the host name
6898  if (urlPrepended.isValid() && (!urlPrepended.host().isEmpty() || !urlPrepended.path().isEmpty()))
6899  {
6900  int dotIndex = trimmedString.indexOf(QLatin1Char('.'));
6901  const QString hostscheme = trimmedString.left(dotIndex).toLower();
6902  if (hostscheme == QLatin1String("ftp"))
6903  urlPrepended.setScheme(QLatin1String("ftp"));
6904  return urlPrepended;
6905  }
6906 
6907  return QUrl();
6908 }
bool isValid() const
Returns true if the URL is valid; otherwise returns false.
Definition: qurl.cpp:4303
static bool isAbsolutePath(const QString &path)
Returns true if path is absolute; returns false if it is relative.
Definition: qdir.h:192
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
QString scheme() const
Returns the scheme of the URL.
Definition: qurl.cpp:4550
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition: qurl.cpp:6374
static QUrl fromEncoded(const QByteArray &url)
Parses input and returns the corresponding QUrl.
Definition: qurl.cpp:5964
QUrl()
Constructs an empty QUrl object.
Definition: qurl.cpp:4272
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ hasEncodedQueryItem()

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.

Since
4.4

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.

See also
hasQueryItem()

Definition at line 5394 of file qurl.cpp.

Referenced by hasQueryItem().

5395 {
5396  if (!d) return false;
5397  QMutexLocker lock(&d->mutex);
5399 
5400  int pos = 0;
5401  const char *query = d->query.constData();
5402  while (pos < d->query.size()) {
5403  int valuedelim, end;
5404  d->queryItem(pos, &valuedelim, &end);
5405  if (key == QByteArray::fromRawData(query + pos, valuedelim - pos))
5406  return true;
5407  pos = end + 1;
5408  }
5409  return false;
5410 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
static QByteArray fromRawData(const char *, int size)
Constructs a QByteArray that uses the first size bytes of the data array.
void queryItem(int pos, int *value, int *end)
Definition: qurl.cpp:3727
QByteArray query
Definition: qurl.cpp:361
QUrlPrivate * d
Definition: qurl.h:279
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
static const KeyPair *const end

◆ hasFragment()

bool QUrl::hasFragment ( ) const

Returns true if this URL contains a fragment (i.

Since
4.2

e., if # was seen on it).

\sa fragment(), setFragment()

Definition at line 5773 of file qurl.cpp.

Referenced by QTextDocument::loadResource(), and QTextBrowserPrivate::resolveUrl().

5774 {
5775  if (!d) return false;
5776  QMutexLocker lock(&d->mutex);
5778 
5779  return d->hasFragment;
5780 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
bool hasFragment
Definition: qurl.cpp:374
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394

◆ hasQuery()

bool QUrl::hasQuery ( ) const

Returns true if this URL contains a Query (i.

Since
4.2

e., if ? was seen on it).

\sa hasQueryItem(), encodedQuery()

Definition at line 5058 of file qurl.cpp.

Referenced by QHttpNetworkRequestPrivate::header().

5059 {
5060  if (!d) return false;
5061  QMutexLocker lock(&d->mutex);
5063 
5064  return d->hasQuery;
5065 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
QUrlPrivate * d
Definition: qurl.h:279
bool hasQuery
Definition: qurl.cpp:373
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394

◆ hasQueryItem()

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.

See also
hasEncodedQueryItem()

Definition at line 5372 of file qurl.cpp.

5373 {
5374  if (!d) return false;
5376 }
static QByteArray toPercentEncoding(const QString &, const QByteArray &exclude=QByteArray(), const QByteArray &include=QByteArray())
Returns an encoded copy of input.
Definition: qurl.cpp:6009
static const char queryExcludeChars[]
Definition: qurl.cpp:3547
QUrlPrivate * d
Definition: qurl.h:279
bool hasEncodedQueryItem(const QByteArray &key) const
Returns true if there is a query string pair whose key is equal to key from the URL.
Definition: qurl.cpp:5394

◆ host()

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

4838 {
4839  if (!d) return QString();
4840  QMutexLocker lock(&d->mutex);
4842 
4843  QString result = d->canonicalHost();
4844  if (result.startsWith(QLatin1Char('[')))
4845  return result.mid(1, result.length() - 2);
4846  return result;
4847 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
The QString class provides a Unicode character string.
Definition: qstring.h:83
int stateFlags
Definition: qurl.cpp:387
QUrlPrivate * d
Definition: qurl.h:279
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
QString canonicalHost() const
Definition: qurl.cpp:3479
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ idnWhitelist()

QStringList QUrl::idnWhitelist ( )
static

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

Since
4.2

See setIdnWhitelist() for the rationale of this list.

Definition at line 6175 of file qurl.cpp.

6176 {
6177  if (user_idn_whitelist)
6178  return *user_idn_whitelist;
6179  QStringList list;
6180  unsigned int i = 0;
6181  while (i < sizeof(idn_whitelist)/sizeof(const char *)) {
6182  list << QLatin1String(idn_whitelist[i]);
6183  ++i;
6184  }
6185  return list;
6186 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static const char *const idn_whitelist[]
Definition: qurl.cpp:3227
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static QStringList * user_idn_whitelist
Definition: qurl.cpp:3251

◆ isDetached()

bool QUrl::isDetached ( ) const
Warning
This function is not part of the public interface.

Definition at line 6356 of file qurl.cpp.

6357 {
6358  return !d || d->ref == 1;
6359 }
QAtomicInt ref
Definition: qurl.cpp:354
QUrlPrivate * d
Definition: qurl.h:279

◆ isEmpty()

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

4318 {
4319  if (!d) return true;
4320 
4321  QMutexLocker lock(&d->mutex);
4323  return d->encodedOriginal.isEmpty();
4324  else
4325  return d->scheme.isEmpty() // no encodedScheme
4328  && d->host.isEmpty() // no encodedHost
4329  && d->port == -1
4330  && d->path.isEmpty() && d->encodedPath.isEmpty()
4331  && d->query.isEmpty()
4332  && d->fragment.isEmpty() && d->encodedFragment.isEmpty();
4333 }
QString path
Definition: qurl.cpp:360
QByteArray encodedPath
Definition: qurl.cpp:367
QByteArray encodedUserName
Definition: qurl.cpp:365
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
QString fragment
Definition: qurl.cpp:362
QString password
Definition: qurl.cpp:358
QByteArray encodedPassword
Definition: qurl.cpp:366
int stateFlags
Definition: qurl.cpp:387
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QByteArray query
Definition: qurl.cpp:361
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QByteArray encodedOriginal
Definition: qurl.cpp:364
QString scheme
Definition: qurl.cpp:356
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
QString host
Definition: qurl.cpp:359
QByteArray encodedFragment
Definition: qurl.cpp:368
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
int port
Definition: qurl.cpp:370
QString userName
Definition: qurl.cpp:357

◆ isLocalFile()

bool QUrl::isLocalFile ( ) const

Returns true if this URL is pointing to a local file path.

Since
4.8 A URL is a local file path if the scheme is "file".

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

See also
fromLocalFile(), toLocalFile()

Definition at line 6453 of file qurl.cpp.

Referenced by QNetworkAccessFileBackendFactory::create(), QNetworkAccessManager::createRequest(), and toLocalFile().

6454 {
6455  if (!d) return false;
6456  QMutexLocker lock(&d->mutex);
6458 
6459  if (d->scheme.compare(QLatin1String("file"), Qt::CaseInsensitive) != 0)
6460  return false; // not file
6461  return true;
6462 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
int compare(const QString &s) const
Definition: qstring.cpp:5037
QString scheme
Definition: qurl.cpp:356
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394

◆ isParentOf()

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.

6470 {
6471  QString childPath = childUrl.path();
6472 
6473  if (!d)
6474  return ((childUrl.scheme().isEmpty())
6475  && (childUrl.authority().isEmpty())
6476  && childPath.length() > 0 && childPath.at(0) == QLatin1Char('/'));
6477 
6478  QMutexLocker lock(&d->mutex);
6480  lock.unlock();
6481 
6482  QString ourPath = path();
6483 
6484  return ((childUrl.scheme().isEmpty() || scheme() == childUrl.scheme())
6485  && (childUrl.authority().isEmpty() || authority() == childUrl.authority())
6486  && childPath.startsWith(ourPath)
6487  && ((ourPath.endsWith(QLatin1Char('/')) && childPath.length() > ourPath.length())
6488  || (!ourPath.endsWith(QLatin1Char('/'))
6489  && childPath.length() > ourPath.length() && childPath.at(ourPath.length()) == QLatin1Char('/'))));
6490 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
void unlock()
Unlocks the lock.
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
The QString class provides a Unicode character string.
Definition: qstring.h:83
int stateFlags
Definition: qurl.cpp:387
QString path() const
Returns the path of the URL.
Definition: qurl.cpp:4977
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QString authority() const
Returns the authority of the URL if it is defined; otherwise an empty string is returned.
Definition: qurl.cpp:4592
QUrlPrivate * d
Definition: qurl.h:279
QString scheme() const
Returns the scheme of the URL.
Definition: qurl.cpp:4550
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ isRelative()

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

5881 {
5882  if (!d) return true;
5883  QMutexLocker lock(&d->mutex);
5885 
5886  return d->scheme.isEmpty();
5887 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QString scheme
Definition: qurl.cpp:356
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394

◆ isValid()

bool QUrl::isValid ( ) const

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

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

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

Definition at line 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().

4304 {
4305  if (!d) return false;
4306 
4307  QMutexLocker lock(&d->mutex);
4310 
4311  return d->isValid && d->isHostValid;
4312 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
void validate() const
Definition: qurl.cpp:3818
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
bool isValid
Definition: qurl.cpp:375
bool isHostValid
Definition: qurl.cpp:376

◆ operator!=()

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

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

Definition at line 6256 of file qurl.cpp.

6257 {
6258  return !(*this == url);
6259 }

◆ operator<()

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

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

Warning
This function is not part of the public interface.

This provides a means of ordering URLs.

Definition at line 6228 of file qurl.cpp.

6229 {
6230  QOrderedMutexLocker(d ? &d->mutex : 0, url.d ? &url.d->mutex : 0);
6231  if (!d) return url.d ? QByteArray() < url.d->normalized() : false;
6233  if (!url.d) return d->normalized() < QByteArray();
6234  if (!QURL_HASFLAG(url.d->stateFlags, QUrlPrivate::Parsed)) url.d->parse();
6235  return d->normalized() < url.d->normalized();
6236 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
QUrlPrivate * d
Definition: qurl.h:279
const QByteArray & normalized() const
Definition: qurl.cpp:4082
QMutex mutex
Definition: qurl.cpp:394

◆ operator=() [1/2]

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

Assigns the specified url to this object.

Definition at line 6264 of file qurl.cpp.

6265 {
6266  if (!d) {
6267  if (url.d) {
6268  url.d->ref.ref();
6269  d = url.d;
6270  }
6271  } else {
6272  if (url.d)
6273  qAtomicAssign(d, url.d);
6274  else
6275  clear();
6276  }
6277  return *this;
6278 }
void clear()
Resets the content of the QUrl.
Definition: qurl.cpp:4340
QUrlPrivate * d
Definition: qurl.h:279
void qAtomicAssign(T *&d, T *x)
This is a helper for the assignment operators of implicitly shared classes.
Definition: qatomic.h:195

◆ operator=() [2/2]

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

Assigns the specified url to this object.

Definition at line 6283 of file qurl.cpp.

6284 {
6285  if (url.isEmpty()) {
6286  clear();
6287  } else {
6288  QUrl tmp(url);
6289  if (!d) d = new QUrlPrivate;
6290  qAtomicAssign(d, tmp.d);
6291  }
6292  return *this;
6293 }
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
void clear()
Resets the content of the QUrl.
Definition: qurl.cpp:4340
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QUrlPrivate * d
Definition: qurl.h:279
void qAtomicAssign(T *&d, T *x)
This is a helper for the assignment operators of implicitly shared classes.
Definition: qatomic.h:195

◆ operator==()

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.

6243 {
6244  if (!d) return url.isEmpty();
6245  if (!url.d) return isEmpty();
6246  QOrderedMutexLocker(&d->mutex, &url.d->mutex);
6248  if (!QURL_HASFLAG(url.d->stateFlags, QUrlPrivate::Parsed)) url.d->parse();
6249  return d->normalized() == url.d->normalized();
6250 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
Definition: qurl.cpp:4317
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
QUrlPrivate * d
Definition: qurl.h:279
const QByteArray & normalized() const
Definition: qurl.cpp:4082
QMutex mutex
Definition: qurl.cpp:394

◆ password()

QString QUrl::password ( ) const

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

See also
setPassword()

Definition at line 4754 of file qurl.cpp.

Referenced by QNetworkAccessManagerPrivate::authenticationRequired(), QNetworkAccessAuthenticationManager::fetchCachedCredentials(), QNetworkAccessFtpBackend::open(), QHttpNetworkConnectionChannel::sendRequest(), setEncodedPassword(), and setPassword().

4755 {
4756  if (!d) return QString();
4757  QMutexLocker lock(&d->mutex);
4759 
4760  d->userInfo(); // causes the unencoded form to be set
4761  return d->password;
4762 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString password
Definition: qurl.cpp:358
int stateFlags
Definition: qurl.cpp:387
QString userInfo(QUrl::FormattingOptions options=QUrl::None) const
Definition: qurl.cpp:3673
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394

◆ path()

QString QUrl::path ( ) const

Returns the path of the URL.

See also
setPath()

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

4978 {
4979  if (!d) return QString();
4980  QMutexLocker lock(&d->mutex);
4982 
4983  if (d->path.isNull()) {
4984  QUrlPrivate *that = const_cast<QUrlPrivate *>(d);
4986  }
4987  return d->path;
4988 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
QString path
Definition: qurl.cpp:360
QByteArray encodedPath
Definition: qurl.cpp:367
static QString fromPercentEncodingHelper(const QByteArray &ba)
Definition: qurl.cpp:242
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
The QString class provides a Unicode character string.
Definition: qstring.h:83
int stateFlags
Definition: qurl.cpp:387
QUrlPrivate * d
Definition: qurl.h:279
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394

◆ port() [1/2]

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

4917 {
4918  if (!d) return -1;
4919  QMutexLocker lock(&d->mutex);
4922  return d->port;
4923 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
void validate() const
Definition: qurl.cpp:3818
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
int port
Definition: qurl.cpp:370

◆ port() [2/2]

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.

Since
4.1

Example:

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

Definition at line 4939 of file qurl.cpp.

4940 {
4941  if (!d) return defaultPort;
4942  QMutexLocker lock(&d->mutex);
4944  return d->port == -1 ? defaultPort : d->port;
4945 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
int port
Definition: qurl.cpp:370

◆ queryItems()

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

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

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

Definition at line 5305 of file qurl.cpp.

5306 {
5307  if (!d) return QList<QPair<QString, QString> >();
5308  QMutexLocker lock(&d->mutex);
5310 
5312 
5313  int pos = 0;
5314  const char *query = d->query.constData();
5315  while (pos < d->query.size()) {
5316  int valuedelim, end;
5317  d->queryItem(pos, &valuedelim, &end);
5318  QByteArray q(query + pos, valuedelim - pos);
5319  if (valuedelim < end) {
5320  QByteArray v(query + valuedelim + 1, end - valuedelim - 1);
5321  itemMap += qMakePair(fromPercentEncodingMutable(&q),
5323  } else {
5324  itemMap += qMakePair(fromPercentEncodingMutable(&q), QString());
5325  }
5326  pos = end + 1;
5327  }
5328 
5329  return itemMap;
5330 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
The QString class provides a Unicode character string.
Definition: qstring.h:83
int stateFlags
Definition: qurl.cpp:387
static QString fromPercentEncodingMutable(QByteArray *ba)
Definition: qurl.cpp:251
void queryItem(int pos, int *value, int *end)
Definition: qurl.cpp:3727
QByteArray query
Definition: qurl.cpp:361
QUrlPrivate * d
Definition: qurl.h:279
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
static const KeyPair *const end
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ queryItemValue()

QString QUrl::queryItemValue ( const QString key) const

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

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

Definition at line 5422 of file qurl.cpp.

5423 {
5424  if (!d) return QString();
5426  return fromPercentEncodingMutable(&tmp);
5427 }
static QByteArray toPercentEncoding(const QString &, const QByteArray &exclude=QByteArray(), const QByteArray &include=QByteArray())
Returns an encoded copy of input.
Definition: qurl.cpp:6009
QByteArray encodedQueryItemValue(const QByteArray &key) const
Returns the first query string value whose key is equal to key from the URL.
Definition: qurl.cpp:5445
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QString fromPercentEncodingMutable(QByteArray *ba)
Definition: qurl.cpp:251
static const char queryExcludeChars[]
Definition: qurl.cpp:3547
QUrlPrivate * d
Definition: qurl.h:279

◆ queryPairDelimiter()

char QUrl::queryPairDelimiter ( ) const

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

Definition at line 5103 of file qurl.cpp.

5104 {
5105  if (!d) return '&';
5106  return d->pairDelimiter;
5107 }
QUrlPrivate * d
Definition: qurl.h:279
char pairDelimiter
Definition: qurl.cpp:379

◆ queryValueDelimiter()

char QUrl::queryValueDelimiter ( ) const

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

Definition at line 5113 of file qurl.cpp.

5114 {
5115  if (!d) return '=';
5116  return d->valueDelimiter;
5117 }
QUrlPrivate * d
Definition: qurl.h:279
char valueDelimiter
Definition: qurl.cpp:378

◆ removeAllEncodedQueryItems()

void QUrl::removeAllEncodedQueryItems ( const QByteArray key)

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

Since
4.4

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.

See also
removeQueryItem()

Definition at line 5617 of file qurl.cpp.

Referenced by removeAllQueryItems().

5618 {
5619  if (!d) return;
5620  QMutexLocker lock(&d->mutex);
5622  detach(lock);
5623 
5624  int pos = 0;
5625  const char *query = d->query.constData();
5626  while (pos < d->query.size()) {
5627  int valuedelim, end;
5628  d->queryItem(pos, &valuedelim, &end);
5629  if (key == QByteArray::fromRawData(query + pos, valuedelim - pos)) {
5630  if (end < d->query.size())
5631  ++end; // remove additional '%'
5632  d->query.remove(pos, end - pos);
5633  query = d->query.constData(); //required if remove detach;
5634  } else {
5635  pos = end + 1;
5636  }
5637  }
5638 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
void detach()
Forces a detach.
Definition: qurl.cpp:6313
static QByteArray fromRawData(const char *, int size)
Constructs a QByteArray that uses the first size bytes of the data array.
void queryItem(int pos, int *value, int *end)
Definition: qurl.cpp:3727
QByteArray query
Definition: qurl.cpp:361
QUrlPrivate * d
Definition: qurl.h:279
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
static const KeyPair *const end
QByteArray & remove(int index, int len)
Removes len bytes from the array, starting at index position pos, and returns a reference to the arra...

◆ removeAllQueryItems()

void QUrl::removeAllQueryItems ( const QString key)

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

See also
removeQueryItem()

Definition at line 5595 of file qurl.cpp.

5596 {
5597  if (!d) return;
5599 }
static QByteArray toPercentEncoding(const QString &, const QByteArray &exclude=QByteArray(), const QByteArray &include=QByteArray())
Returns an encoded copy of input.
Definition: qurl.cpp:6009
static const char queryExcludeChars[]
Definition: qurl.cpp:3547
QUrlPrivate * d
Definition: qurl.h:279
void removeAllEncodedQueryItems(const QByteArray &key)
Removes all the query string pairs whose key is equal to key from the URL.
Definition: qurl.cpp:5617

◆ removeEncodedQueryItem()

void QUrl::removeEncodedQueryItem ( const QByteArray key)

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

Since
4.4

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.

See also
removeQueryItem(), removeAllQueryItems()

Definition at line 5567 of file qurl.cpp.

Referenced by removeQueryItem().

5568 {
5569  if (!d) return;
5570  QMutexLocker lock(&d->mutex);
5572  detach(lock);
5573 
5574  int pos = 0;
5575  const char *query = d->query.constData();
5576  while (pos < d->query.size()) {
5577  int valuedelim, end;
5578  d->queryItem(pos, &valuedelim, &end);
5579  if (key == QByteArray::fromRawData(query + pos, valuedelim - pos)) {
5580  if (end < d->query.size())
5581  ++end; // remove additional '%'
5582  d->query.remove(pos, end - pos);
5583  return;
5584  }
5585  pos = end + 1;
5586  }
5587 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
void detach()
Forces a detach.
Definition: qurl.cpp:6313
static QByteArray fromRawData(const char *, int size)
Constructs a QByteArray that uses the first size bytes of the data array.
void queryItem(int pos, int *value, int *end)
Definition: qurl.cpp:3727
QByteArray query
Definition: qurl.cpp:361
QUrlPrivate * d
Definition: qurl.h:279
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
static const KeyPair *const end
QByteArray & remove(int index, int len)
Removes len bytes from the array, starting at index position pos, and returns a reference to the arra...

◆ removeQueryItem()

void QUrl::removeQueryItem ( const QString key)

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

See also
removeAllQueryItems()

Definition at line 5545 of file qurl.cpp.

5546 {
5547  if (!d) return;
5549 }
static QByteArray toPercentEncoding(const QString &, const QByteArray &exclude=QByteArray(), const QByteArray &include=QByteArray())
Returns an encoded copy of input.
Definition: qurl.cpp:6009
static const char queryExcludeChars[]
Definition: qurl.cpp:3547
QUrlPrivate * d
Definition: qurl.h:279
void removeEncodedQueryItem(const QByteArray &key)
Removes the first query string pair whose key is equal to key from the URL.
Definition: qurl.cpp:5567

◆ resolved()

QUrl QUrl::resolved ( const QUrl relative) const

Returns the result of the merge of this URL with relative.

This URL is used as a base to convert relative to an absolute URL.

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

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

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

See also
isRelative()

Definition at line 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().

5820 {
5821  if (!d) return relative;
5822  if (!relative.d) return *this;
5823 
5824  QOrderedMutexLocker locker(&d->mutex, &relative.d->mutex);
5825 
5827  if (!QURL_HASFLAG(relative.d->stateFlags, QUrlPrivate::Parsed))
5828  relative.d->parse();
5829 
5830  d->ensureEncodedParts();
5831  relative.d->ensureEncodedParts();
5832 
5833  QUrl t;
5834  // be non strict and allow scheme in relative url
5835  if (!relative.d->scheme.isEmpty() && relative.d->scheme != d->scheme) {
5836  t = relative;
5837  // t.detach(locker) would unlock, so bypass it
5838  qAtomicDetach(t.d);
5839  } else {
5840  if (!relative.d->authority().isEmpty()) {
5841  t = relative;
5842  qAtomicDetach(t.d);
5843  } else {
5844  t.d = new QUrlPrivate;
5845  if (relative.d->encodedPath.isEmpty()) {
5846  t.d->encodedPath = d->encodedPath;
5847  t.d->query = relative.d->hasQuery ? relative.d->query : d->query;
5848  } else {
5849  t.d->encodedPath = relative.d->encodedPath.at(0) == '/'
5850  ? relative.d->encodedPath
5851  : d->mergePaths(relative.d->encodedPath);
5852  t.d->query = relative.d->query;
5853  }
5854  t.d->hasQuery = !t.d->query.isNull();
5857  t.d->host = d->host;
5858  t.d->port = d->port;
5859  }
5860  t.setScheme(d->scheme);
5861  }
5862  t.setFragment(relative.d->fragmentImpl());
5864  t.d->path.clear();
5865 
5866 #if defined(QURL_DEBUG)
5867  qDebug("QUrl(\"%s\").resolved(\"%s\") = \"%s\"",
5868  d->toEncoded().constData(),
5869  relative.d->toEncoded().constData(),
5870  t.toEncoded().constData());
5871 #endif
5872  return t;
5873 }
void qAtomicDetach(T *&d)
This is a helper for the detach method of implicitly shared classes.
Definition: qatomic.h:214
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
QString path
Definition: qurl.cpp:360
QByteArray encodedPath
Definition: qurl.cpp:367
QByteArray encodedUserName
Definition: qurl.cpp:365
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
static void removeDotsFromPath(QByteArray *path)
Definition: qurl.cpp:3746
QByteArray encodedPassword
Definition: qurl.cpp:366
QString fragmentImpl() const
Definition: qurl.cpp:5696
int stateFlags
Definition: qurl.cpp:387
Q_CORE_EXPORT void qDebug(const char *,...)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QByteArray toEncoded(QUrl::FormattingOptions options=QUrl::None) const
Definition: qurl.cpp:3996
QByteArray query
Definition: qurl.cpp:361
bool isNull() const
Returns true if this byte array is null; otherwise returns false.
QUrlPrivate * d
Definition: qurl.h:279
void setFragment(const QString &fragment)
Sets the fragment of the URL to fragment.
Definition: qurl.cpp:5669
QByteArray toEncoded(FormattingOptions options=None) const
Returns the encoded representation of the URL if it&#39;s valid; otherwise an empty QByteArray is returne...
Definition: qurl.cpp:5949
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
bool hasQuery
Definition: qurl.cpp:373
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
QString scheme
Definition: qurl.cpp:356
QByteArray mergePaths(const QByteArray &relativePath) const
Definition: qurl.cpp:3700
QMutex mutex
Definition: qurl.cpp:394
QString authority(QUrl::FormattingOptions options=QUrl::None) const
Definition: qurl.cpp:3568
QString host
Definition: qurl.cpp:359
void setScheme(const QString &scheme)
Sets the scheme of the URL to scheme.
Definition: qurl.cpp:4533
void ensureEncodedParts() const
Definition: qurl.cpp:3550
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
int port
Definition: qurl.cpp:370
char at(int i) const
Returns the character at index position i in the byte array.
Definition: qbytearray.h:413

◆ scheme()

QString QUrl::scheme ( ) const

Returns the scheme of the URL.

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

See also
setScheme(), isRelative()

Definition at line 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().

4551 {
4552  if (!d) return QString();
4553  QMutexLocker lock(&d->mutex);
4555 
4556  return d->scheme;
4557 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
The QString class provides a Unicode character string.
Definition: qstring.h:83
int stateFlags
Definition: qurl.cpp:387
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QString scheme
Definition: qurl.cpp:356
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394

◆ setAuthority()

void QUrl::setAuthority ( const QString authority)

Sets the authority of the URL to authority.

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

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

The following example shows a valid authority string:

qurl-authority.png

Definition at line 4575 of file qurl.cpp.

4576 {
4577  if (!d) d = new QUrlPrivate;
4578 
4579  QMutexLocker lock(&d->mutex);
4581  detach(lock);
4583  d->setAuthority(authority);
4584 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
#define QURL_UNSETFLAG(a, b)
Definition: qurl.cpp:277
void detach()
Forces a detach.
Definition: qurl.cpp:6313
void setAuthority(const QString &auth)
Definition: qurl.cpp:3585
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394

◆ setEncodedFragment()

void QUrl::setEncodedFragment ( const QByteArray fragment)

Sets the URL's fragment to the percent-encoded fragment.

Since
4.4

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

qurl-fragment.png

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

Passing an argument of 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 "#").

See also
setFragment(), encodedFragment()

Definition at line 5727 of file qurl.cpp.

5728 {
5729  if (!d) d = new QUrlPrivate;
5730  QMutexLocker lock(&d->mutex);
5732  detach(lock);
5734 
5736  d->hasFragment = !fragment.isNull();
5737  d->fragment.clear();
5738 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
bool hasFragment
Definition: qurl.cpp:374
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
QString fragment
Definition: qurl.cpp:362
QString fragment() const
Returns the fragment of the URL.
Definition: qurl.cpp:5687
int stateFlags
Definition: qurl.cpp:387
#define QURL_UNSETFLAG(a, b)
Definition: qurl.cpp:277
void detach()
Forces a detach.
Definition: qurl.cpp:6313
bool isNull() const
Returns true if this byte array is null; otherwise returns false.
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
QByteArray encodedFragment
Definition: qurl.cpp:368

◆ setEncodedHost()

void QUrl::setEncodedHost ( const QByteArray host)

Sets the URL's host to the ACE- or percent-encoded host.

Since
4.4

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

Definition at line 4861 of file qurl.cpp.

4862 {
4864 }
static QString fromPercentEncodingHelper(const QByteArray &ba)
Definition: qurl.cpp:242
void setHost(const QString &host)
Sets the host of the URL to host.
Definition: qurl.cpp:4821

◆ setEncodedPassword()

void QUrl::setEncodedPassword ( const QByteArray password)

Sets the URL's password to the percent-encoded password.

Since
4.4

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.

See also
setPassword(), encodedPassword(), setUserInfo()

Definition at line 4780 of file qurl.cpp.

4781 {
4782  if (!d) d = new QUrlPrivate;
4783  QMutexLocker lock(&d->mutex);
4785  detach(lock);
4787 
4789  d->password.clear();
4790 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
QString password
Definition: qurl.cpp:358
QByteArray encodedPassword
Definition: qurl.cpp:366
int stateFlags
Definition: qurl.cpp:387
#define QURL_UNSETFLAG(a, b)
Definition: qurl.cpp:277
void detach()
Forces a detach.
Definition: qurl.cpp:6313
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
QString password() const
Returns the password of the URL if it is defined; otherwise an empty string is returned.
Definition: qurl.cpp:4754

◆ setEncodedPath()

void QUrl::setEncodedPath ( const QByteArray path)

Sets the URL's path to the percent-encoded path.

Since
4.4

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

qurl-ftppath.png

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

qurl-mailtopath.png

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.

See also
setPath(), encodedPath(), setUserInfo()

Definition at line 5013 of file qurl.cpp.

5014 {
5015  if (!d) d = new QUrlPrivate;
5016  QMutexLocker lock(&d->mutex);
5018  detach(lock);
5020 
5021  d->encodedPath = path;
5022  d->path.clear();
5023 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
QString path
Definition: qurl.cpp:360
QByteArray encodedPath
Definition: qurl.cpp:367
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
QString path() const
Returns the path of the URL.
Definition: qurl.cpp:4977
#define QURL_UNSETFLAG(a, b)
Definition: qurl.cpp:277
void detach()
Forces a detach.
Definition: qurl.cpp:6313
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394

◆ setEncodedQuery()

void QUrl::setEncodedQuery ( const QByteArray query)

Sets the query string of the URL to query.

The string is inserted as-is, and no further encoding is performed when calling toEncoded().

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

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

See also
encodedQuery(), hasQuery()

Definition at line 5136 of file qurl.cpp.

Referenced by makeCacheKey().

5137 {
5138  if (!d) d = new QUrlPrivate;
5139  QMutexLocker lock(&d->mutex);
5141  detach(lock);
5143 
5144  d->query = query;
5145  d->hasQuery = !query.isNull();
5146 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
#define QURL_UNSETFLAG(a, b)
Definition: qurl.cpp:277
void detach()
Forces a detach.
Definition: qurl.cpp:6313
QByteArray query
Definition: qurl.cpp:361
bool isNull() const
Returns true if this byte array is null; otherwise returns false.
QUrlPrivate * d
Definition: qurl.h:279
bool hasQuery
Definition: qurl.cpp:373
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394

◆ setEncodedQueryItems()

void QUrl::setEncodedQueryItems ( const QList< QPair< QByteArray, QByteArray > > &  query)

Sets the query string of the URL to the encoded version of query.

Since
4.4

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.

See also
setQueryDelimiters(), encodedQueryItems(), setQueryItems()

Definition at line 5205 of file qurl.cpp.

5206 {
5207  if (!d) d = new QUrlPrivate;
5208  QMutexLocker lock(&d->mutex);
5210  detach(lock);
5211 
5212  QByteArray queryTmp;
5213  for (int i = 0; i < query.size(); i++) {
5214  if (i) queryTmp += d->pairDelimiter;
5215  queryTmp += query.at(i).first;
5216  queryTmp += d->valueDelimiter;
5217  queryTmp += query.at(i).second;
5218  }
5219 
5220  d->query = queryTmp;
5221  d->hasQuery = !query.isEmpty();
5222 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
void detach()
Forces a detach.
Definition: qurl.cpp:6313
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QByteArray query
Definition: qurl.cpp:361
QUrlPrivate * d
Definition: qurl.h:279
bool hasQuery
Definition: qurl.cpp:373
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
char valueDelimiter
Definition: qurl.cpp:378
char pairDelimiter
Definition: qurl.cpp:379

◆ setEncodedUrl() [1/2]

void QUrl::setEncodedUrl ( const QByteArray encodedUrl)

Constructs a URL by parsing the contents of encodedUrl.

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

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

See also
setUrl()

Definition at line 4429 of file qurl.cpp.

Referenced by fromEncoded().

4430 {
4431  setEncodedUrl(encodedUrl, TolerantMode);
4432 }
void setEncodedUrl(const QByteArray &url)
Constructs a URL by parsing the contents of encodedUrl.
Definition: qurl.cpp:4429

◆ setEncodedUrl() [2/2]

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.

4450 {
4451  if (!d) d = new QUrlPrivate;
4452  QMutexLocker lock(&d->mutex);
4453  detach(lock);
4454  d->clear();
4455  d->setEncodedUrl(encodedUrl, parsingMode);
4456 }
void clear()
Definition: qurl.cpp:3968
void detach()
Forces a detach.
Definition: qurl.cpp:6313
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
void setEncodedUrl(const QByteArray &encodedUrl, QUrl::ParsingMode parsingMode)
Definition: qurl.cpp:4458

◆ setEncodedUserName()

void QUrl::setEncodedUserName ( const QByteArray userName)

Sets the URL's user name to the percent-encoded userName.

Since
4.4

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.

See also
setUserName(), encodedUserName(), setUserInfo()

Definition at line 4694 of file qurl.cpp.

4695 {
4696  if (!d) d = new QUrlPrivate;
4697  QMutexLocker lock(&d->mutex);
4699  detach(lock);
4701 
4703  d->userName.clear();
4704 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
QByteArray encodedUserName
Definition: qurl.cpp:365
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
#define QURL_UNSETFLAG(a, b)
Definition: qurl.cpp:277
void detach()
Forces a detach.
Definition: qurl.cpp:6313
QUrlPrivate * d
Definition: qurl.h:279
QString userName() const
Returns the user name of the URL if it is defined; otherwise an empty string is returned.
Definition: qurl.cpp:4667
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
QString userName
Definition: qurl.cpp:357

◆ setFragment()

void QUrl::setFragment ( const QString fragment)

Sets the fragment of the URL to fragment.

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

qurl-fragment.png

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

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

See also
fragment(), hasFragment()

Definition at line 5669 of file qurl.cpp.

Referenced by authenticationKey(), QPatternist::ReportContext::codeFromURI(), proxyAuthenticationKey(), qmlxmlhttprequest_open(), resolved(), QTextBrowserPrivate::setSource(), QNetworkCacheMetaData::setUrl(), and QNetworkDiskCachePrivate::uniqueFileName().

5670 {
5671  if (!d) d = new QUrlPrivate;
5672  QMutexLocker lock(&d->mutex);
5674  detach(lock);
5676 
5677  d->fragment = fragment;
5678  d->hasFragment = !fragment.isNull();
5679  d->encodedFragment.clear();
5680 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
bool hasFragment
Definition: qurl.cpp:374
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
QString fragment
Definition: qurl.cpp:362
QString fragment() const
Returns the fragment of the URL.
Definition: qurl.cpp:5687
int stateFlags
Definition: qurl.cpp:387
#define QURL_UNSETFLAG(a, b)
Definition: qurl.cpp:277
void detach()
Forces a detach.
Definition: qurl.cpp:6313
QUrlPrivate * d
Definition: qurl.h:279
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
QByteArray encodedFragment
Definition: qurl.cpp:368
void clear()
Clears the contents of the byte array and makes it empty.

◆ setHost()

void QUrl::setHost ( const QString host)

Sets the host of the URL to host.

The host is part of the authority.

See also
host(), setAuthority()

Definition at line 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().

4822 {
4823  if (!d) d = new QUrlPrivate;
4824  QMutexLocker lock(&d->mutex);
4826  detach(lock);
4827  d->isHostValid = true;
4829 
4830  d->host = host;
4831 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
QString host() const
Returns the host of the URL if it is defined; otherwise an empty string is returned.
Definition: qurl.cpp:4837
int stateFlags
Definition: qurl.cpp:387
#define QURL_UNSETFLAG(a, b)
Definition: qurl.cpp:277
void detach()
Forces a detach.
Definition: qurl.cpp:6313
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
QString host
Definition: qurl.cpp:359
bool isHostValid
Definition: qurl.cpp:376

◆ setIdnWhitelist()

void QUrl::setIdnWhitelist ( const QStringList list)
static

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

Since
4.2

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.

6213 {
6214  if (!user_idn_whitelist)
6216  *user_idn_whitelist = list;
6217 }
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static QStringList * user_idn_whitelist
Definition: qurl.cpp:3251

◆ setPassword()

void QUrl::setPassword ( const QString password)

Sets the URL's password to password.

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

See also
password(), setUserInfo()

Definition at line 4736 of file qurl.cpp.

Referenced by qmlxmlhttprequest_open(), QNetworkCacheMetaData::setUrl(), and QNetworkDiskCachePrivate::uniqueFileName().

4737 {
4738  if (!d) d = new QUrlPrivate;
4739  QMutexLocker lock(&d->mutex);
4741  detach(lock);
4743 
4744  d->password = password;
4745  d->encodedPassword.clear();
4746 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
QString password
Definition: qurl.cpp:358
QByteArray encodedPassword
Definition: qurl.cpp:366
int stateFlags
Definition: qurl.cpp:387
#define QURL_UNSETFLAG(a, b)
Definition: qurl.cpp:277
void detach()
Forces a detach.
Definition: qurl.cpp:6313
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
QString password() const
Returns the password of the URL if it is defined; otherwise an empty string is returned.
Definition: qurl.cpp:4754
void clear()
Clears the contents of the byte array and makes it empty.

◆ setPath()

void QUrl::setPath ( const QString path)

Sets the path of the URL to path.

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

qurl-ftppath.png

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

qurl-mailtopath.png
See also
path()

Definition at line 4960 of file qurl.cpp.

Referenced by QMacPasteboardMimeFileUri::convertFromMime(), QMacPasteboardMimeUrl::convertFromMime(), QMacPasteboardMimeFileUri::convertToMime(), QMacPasteboardMimeUrl::convertToMime(), fromLocalFile(), isParentOf(), QNetworkAccessFileBackend::open(), QNetworkAccessFtpBackend::open(), and QNetworkReplyFileImpl::QNetworkReplyFileImpl().

4961 {
4962  if (!d) d = new QUrlPrivate;
4963  QMutexLocker lock(&d->mutex);
4965  detach(lock);
4967 
4968  d->path = path;
4969  d->encodedPath.clear();
4970 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
QString path
Definition: qurl.cpp:360
QByteArray encodedPath
Definition: qurl.cpp:367
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
QString path() const
Returns the path of the URL.
Definition: qurl.cpp:4977
#define QURL_UNSETFLAG(a, b)
Definition: qurl.cpp:277
void detach()
Forces a detach.
Definition: qurl.cpp:6313
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
void clear()
Clears the contents of the byte array and makes it empty.

◆ setPort()

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

4898 {
4899  if (!d) d = new QUrlPrivate;
4900  QMutexLocker lock(&d->mutex);
4902  detach(lock);
4904 
4905  if (port < -1 || port > 65535) {
4906  qWarning("QUrl::setPort: Out of range");
4907  port = -1;
4908  }
4909 
4910  d->port = port;
4911 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
int port() const
Returns the port of the URL, or -1 if the port is unspecified.
Definition: qurl.cpp:4916
#define QURL_UNSETFLAG(a, b)
Definition: qurl.cpp:277
void detach()
Forces a detach.
Definition: qurl.cpp:6313
Q_CORE_EXPORT void qWarning(const char *,...)
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
int port
Definition: qurl.cpp:370

◆ setQueryDelimiters()

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

Sets the characters used for delimiting between keys and values, and between key-value pairs in the URL's query string.

The default value delimiter is '=' and the default pair delimiter is '&'.

qurl-querystring.png

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

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

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

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

Definition at line 5089 of file qurl.cpp.

5090 {
5091  if (!d) d = new QUrlPrivate;
5092  QMutexLocker lock(&d->mutex);
5093  detach(lock);
5094 
5095  d->valueDelimiter = valueDelimiter;
5096  d->pairDelimiter = pairDelimiter;
5097 }
void detach()
Forces a detach.
Definition: qurl.cpp:6313
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
char valueDelimiter
Definition: qurl.cpp:378
char pairDelimiter
Definition: qurl.cpp:379

◆ setQueryItems()

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

Sets the query string of the URL to an encoded version of query.

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

Note
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::setEncodedQueryItems.
See also
setQueryDelimiters(), queryItems(), setEncodedQueryItems()

Definition at line 5161 of file qurl.cpp.

5162 {
5163  if (!d) d = new QUrlPrivate;
5164  QMutexLocker lock(&d->mutex);
5166  detach(lock);
5167 
5168  char alsoEncode[3];
5169  alsoEncode[0] = d->valueDelimiter;
5170  alsoEncode[1] = d->pairDelimiter;
5171  alsoEncode[2] = 0;
5172 
5173  QByteArray queryTmp;
5174  for (int i = 0; i < query.size(); i++) {
5175  if (i) queryTmp += d->pairDelimiter;
5176  // query = *( pchar / "/" / "?" )
5177  queryTmp += toPercentEncodingHelper(query.at(i).first, queryExcludeChars, alsoEncode);
5178  queryTmp += d->valueDelimiter;
5179  // query = *( pchar / "/" / "?" )
5180  queryTmp += toPercentEncodingHelper(query.at(i).second, queryExcludeChars, alsoEncode);
5181  }
5182 
5183  d->query = queryTmp;
5184  d->hasQuery = !query.isEmpty();
5185 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
static QByteArray toPercentEncodingHelper(const QString &s, const char *exclude, const char *include=0)
Definition: qurl.cpp:233
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
void detach()
Forces a detach.
Definition: qurl.cpp:6313
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static const char queryExcludeChars[]
Definition: qurl.cpp:3547
QByteArray query
Definition: qurl.cpp:361
QUrlPrivate * d
Definition: qurl.h:279
bool hasQuery
Definition: qurl.cpp:373
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
char valueDelimiter
Definition: qurl.cpp:378
char pairDelimiter
Definition: qurl.cpp:379

◆ setScheme()

void QUrl::setScheme ( const QString scheme)

Sets the scheme of the URL to scheme.

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

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

qurl-authority2.png

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

See also
scheme(), isRelative()

Definition at line 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().

4534 {
4535  if (!d) d = new QUrlPrivate;
4536  QMutexLocker lock(&d->mutex);
4538  detach(lock);
4540 
4541  d->scheme = scheme;
4542 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
#define QURL_UNSETFLAG(a, b)
Definition: qurl.cpp:277
void detach()
Forces a detach.
Definition: qurl.cpp:6313
QUrlPrivate * d
Definition: qurl.h:279
QString scheme() const
Returns the scheme of the URL.
Definition: qurl.cpp:4550
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QString scheme
Definition: qurl.cpp:356
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394

◆ setUrl() [1/2]

void QUrl::setUrl ( const QString url)

Constructs a URL by parsing the contents of url.

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

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

See also
setEncodedUrl()

Definition at line 4358 of file qurl.cpp.

Referenced by QUrl().

4359 {
4360  setUrl(url, TolerantMode);
4361 }
void setUrl(const QString &url)
Constructs a URL by parsing the contents of url.
Definition: qurl.cpp:4358

◆ setUrl() [2/2]

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.

See also
setEncodedUrl()

Definition at line 4373 of file qurl.cpp.

4374 {
4375  if (!d) d = new QUrlPrivate;
4376  QMutexLocker lock(&d->mutex);
4377  detach(lock);
4378  d->clear();
4379 
4380  // escape all reserved characters and delimiters
4381  // reserved = gen-delims / sub-delims
4382  if (parsingMode != TolerantMode) {
4384  return;
4385  }
4386 
4387  // Tolerant preprocessing
4388  QString tmp = url;
4389 
4390  // Allow %20 in the QString variant
4391  tmp.replace(QLatin1String("%20"), QLatin1String(" "));
4392 
4393  // Percent-encode unsafe ASCII characters after host part
4394  int start = tmp.indexOf(QLatin1String("//"));
4395  if (start != -1) {
4396  // Has host part, find delimiter
4397  start += 2; // skip "//"
4398  const char delims[] = "/#?";
4399  const char *d = delims;
4400  int hostEnd = -1;
4401  while (*d && (hostEnd = tmp.indexOf(QLatin1Char(*d), start)) == -1)
4402  ++d;
4403  start = (hostEnd == -1) ? -1 : hostEnd + 1;
4404  } else {
4405  start = 0; // Has no host part
4406  }
4407  QByteArray encodedUrl;
4408  if (start != -1) {
4409  QString hostPart = tmp.left(start);
4410  QString otherPart = tmp.mid(start);
4411  encodedUrl = toPercentEncodingHelper(hostPart, ":/?#[]@!$&'()*+,;=")
4412  + toPercentEncodingHelper(otherPart, ":/?#@!$&'()*+,;=");
4413  } else {
4414  encodedUrl = toPercentEncodingHelper(tmp, ABNF_reserved);
4415  }
4416  d->setEncodedUrl(encodedUrl, StrictMode);
4417 }
static QByteArray toPercentEncodingHelper(const QString &s, const char *exclude, const char *include=0)
Definition: qurl.cpp:233
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
void clear()
Definition: qurl.cpp:3968
#define ABNF_reserved
Definition: qurl.cpp:3537
void detach()
Forces a detach.
Definition: qurl.cpp:6313
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
QUrlPrivate * d
Definition: qurl.h:279
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
void setEncodedUrl(const QByteArray &encodedUrl, QUrl::ParsingMode parsingMode)
Definition: qurl.cpp:4458

◆ setUserInfo()

void QUrl::setUserInfo ( const QString userInfo)

Sets the user info of the URL to userInfo.

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

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

qurl-authority3.png
See also
userInfo(), setUserName(), setPassword(), setAuthority()

Definition at line 4615 of file qurl.cpp.

Referenced by QNetworkAccessFtpBackend::ftpDone(), and QHttpNetworkConnectionChannel::sendRequest().

4616 {
4617  if (!d) d = new QUrlPrivate;
4618 
4619  QMutexLocker lock(&d->mutex);
4621  detach(lock);
4623 
4624  d->setUserInfo(userInfo.trimmed());
4625 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
void setUserInfo(const QString &userInfo)
Definition: qurl.cpp:3641
int stateFlags
Definition: qurl.cpp:387
#define QURL_UNSETFLAG(a, b)
Definition: qurl.cpp:277
void detach()
Forces a detach.
Definition: qurl.cpp:6313
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394

◆ setUserName()

void QUrl::setUserName ( const QString userName)

Sets the URL's user name to userName.

The userName is part of the user info element in the authority of the URL, as described in setUserInfo().

See also
setEncodedUserName(), userName(), setUserInfo()

Definition at line 4648 of file qurl.cpp.

Referenced by QNetworkAccessAuthenticationManager::cacheCredentials(), QNetworkAccessFtpBackend::ftpDone(), makeCacheKey(), proxyAuthenticationKey(), and qmlxmlhttprequest_open().

4649 {
4650  if (!d) d = new QUrlPrivate;
4651 
4652  QMutexLocker lock(&d->mutex);
4654  detach(lock);
4656 
4657  d->userName = userName;
4658  d->encodedUserName.clear();
4659 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
QByteArray encodedUserName
Definition: qurl.cpp:365
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
int stateFlags
Definition: qurl.cpp:387
#define QURL_UNSETFLAG(a, b)
Definition: qurl.cpp:277
void detach()
Forces a detach.
Definition: qurl.cpp:6313
QUrlPrivate * d
Definition: qurl.h:279
QString userName() const
Returns the user name of the URL if it is defined; otherwise an empty string is returned.
Definition: qurl.cpp:4667
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
QString userName
Definition: qurl.cpp:357
void clear()
Clears the contents of the byte array and makes it empty.

◆ swap()

void QUrl::swap ( QUrl other)
inline

Swaps URL other with this URL.

Since
4.8

This operation is very fast and never fails.

Definition at line 104 of file qurl.h.

104 { qSwap(d, other.d); }
QUrlPrivate * d
Definition: qurl.h:279
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181

◆ toAce()

QByteArray QUrl::toAce ( const QString domain)
static

Returns the ASCII Compatible Encoding of the given domain name domain.

Since
4.2

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

6159 {
6160  QString result = qt_ACE_do(domain, ToAceOnly);
6161  return result.toLatin1();
6162 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QString qt_ACE_do(const QString &domain, AceOperation op)
Definition: qurl.cpp:3334
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993

◆ toEncoded()

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

5950 {
5951  if (!d) return QByteArray();
5952  QMutexLocker lock(&d->mutex);
5953  return d->toEncoded(options);
5954 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QByteArray toEncoded(QUrl::FormattingOptions options=QUrl::None) const
Definition: qurl.cpp:3996
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394

◆ toLocalFile()

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.

See also
fromLocalFile(), isLocalFile()

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

6413 {
6414  if (!d) return QString();
6415 
6416  // the call to isLocalFile() also ensures that we're parsed
6417  if (!isLocalFile() && !scheme().isEmpty())
6418  return QString();
6419 
6420  QString tmp;
6421  QString ourPath = path();
6422 
6423  QMutexLocker lock(&d->mutex); // for d->host
6424 
6425  // magic for shared drive on windows
6426  if (!d->host.isEmpty()) {
6427  tmp = QLatin1String("//") + d->host + (ourPath.length() > 0 && ourPath.at(0) != QLatin1Char('/')
6428  ? QLatin1Char('/') + ourPath : ourPath);
6429  } else {
6430  tmp = ourPath;
6431  // magic for drives on windows
6432  if (ourPath.length() > 2 && ourPath.at(0) == QLatin1Char('/') && ourPath.at(2) == QLatin1Char(':'))
6433  tmp.remove(0, 1);
6434  }
6435 
6436  return tmp;
6437 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
Definition: qurl.cpp:4317
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString path() const
Returns the path of the URL.
Definition: qurl.cpp:4977
bool isLocalFile() const
Returns true if this URL is pointing to a local file path.
Definition: qurl.cpp:6453
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QUrlPrivate * d
Definition: qurl.h:279
QString scheme() const
Returns the scheme of the URL.
Definition: qurl.cpp:4550
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
QString host
Definition: qurl.cpp:359
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ toPercentEncoding()

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

Returns an encoded copy of input.

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

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

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

Definition at line 6009 of file qurl.cpp.

Referenced by allQueryItemValues(), QPatternist::EncodeString::evaluateSingleton(), hasQueryItem(), queryItemValue(), removeAllQueryItems(), removeQueryItem(), swap(), and QNetworkCookie::toRawForm().

6010 {
6011  return toPercentEncodingHelper(input, exclude.constData(), include.constData());
6012 }
static QByteArray toPercentEncodingHelper(const QString &s, const char *exclude, const char *include=0)
Definition: qurl.cpp:233
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433

◆ topLevelDomain()

QString QUrl::topLevelDomain ( ) const

Returns the TLD (Top-Level Domain) of the URL, (e.

Since
4.8

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.

5795 {
5796  return qTopLevelDomain(host());
5797 }
QString host() const
Returns the host of the URL if it is defined; otherwise an empty string is returned.
Definition: qurl.cpp:4837
Q_CORE_EXPORT QString qTopLevelDomain(const QString &domain)
Return the top-level-domain per Qt&#39;s copy of the Mozilla public suffix list of domain.
Definition: qtldurl.cpp:73

◆ toPunycode()

QByteArray QUrl::toPunycode ( const QString uc)
static

Returns a uc in Punycode encoding.

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

Definition at line 6025 of file qurl.cpp.

6026 {
6027  QString output;
6028  toPunycodeHelper(uc.constData(), uc.size(), &output);
6029  return output.toLatin1();
6030 }
static void toPunycodeHelper(const QChar *s, int ucLength, QString *output)
Definition: qurl.cpp:3140
The QString class provides a Unicode character string.
Definition: qstring.h:83
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712

◆ toString()

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

Returns the human-displayable string representation of the URL.

The output can be customized by passing flags with options.

See also
FormattingOptions, toEncoded()

Definition at line 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().

5897 {
5898  if (!d) return QString();
5899  QString ourPath = path();
5900  QMutexLocker lock(&d->mutex);
5902 
5903  QString url;
5904 
5905  if (!(options & QUrl::RemoveScheme) && !d->scheme.isEmpty())
5906  url += d->scheme + QLatin1Char(':');
5907  if ((options & QUrl::RemoveAuthority) != QUrl::RemoveAuthority) {
5908  bool doFileScheme = d->scheme == QLatin1String("file") && ourPath.startsWith(QLatin1Char('/'));
5909  QString tmp = d->authority(options);
5910  if (!tmp.isNull() || doFileScheme) {
5911  if (doFileScheme && !ourPath.startsWith(QLatin1Char('/')))
5912  url += QLatin1Char('/');
5913  url += QLatin1String("//");
5914  url += tmp;
5915  }
5916  }
5917  if (!(options & QUrl::RemovePath)) {
5918  // check if we need to insert a slash
5919  if ((options & QUrl::RemoveAuthority) != QUrl::RemoveAuthority
5920  && !d->authority(options).isEmpty() && !ourPath.isEmpty() && ourPath.at(0) != QLatin1Char('/'))
5921  url += QLatin1Char('/');
5922  url += ourPath;
5923  // check if we need to remove trailing slashes
5924  while ((options & StripTrailingSlash) && url.endsWith(QLatin1Char('/')))
5925  url.chop(1);
5926  }
5927 
5928  if (!(options & QUrl::RemoveQuery) && d->hasQuery) {
5929  url += QLatin1Char('?');
5930  url += fromPercentEncoding(d->query);
5931  }
5932  if (!(options & QUrl::RemoveFragment) && d->hasFragment) {
5933  url += QLatin1Char('#');
5934  url += d->fragmentImpl();
5935  }
5936 
5937  return url;
5938 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
static QString fromPercentEncoding(const QByteArray &)
Returns a decoded copy of input.
Definition: qurl.cpp:5992
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
bool hasFragment
Definition: qurl.cpp:374
void chop(int n)
Removes n characters from the end of the string.
Definition: qstring.cpp:4623
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString fragmentImpl() const
Definition: qurl.cpp:5696
int stateFlags
Definition: qurl.cpp:387
QString path() const
Returns the path of the URL.
Definition: qurl.cpp:4977
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QByteArray query
Definition: qurl.cpp:361
QUrlPrivate * d
Definition: qurl.h:279
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
bool hasQuery
Definition: qurl.cpp:373
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QString scheme
Definition: qurl.cpp:356
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
QString authority(QUrl::FormattingOptions options=QUrl::None) const
Definition: qurl.cpp:3568
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ userInfo()

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

4632 {
4633  if (!d) return QString();
4634 
4635  QMutexLocker lock(&d->mutex);
4637 
4638  return d->userInfo();
4639 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
The QString class provides a Unicode character string.
Definition: qstring.h:83
int stateFlags
Definition: qurl.cpp:387
QString userInfo(QUrl::FormattingOptions options=QUrl::None) const
Definition: qurl.cpp:3673
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394

◆ userName()

QString QUrl::userName ( ) const

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

See also
setUserName(), encodedUserName()

Definition at line 4667 of file qurl.cpp.

Referenced by QNetworkAccessManagerPrivate::authenticationRequired(), QNetworkAccessAuthenticationManager::cacheCredentials(), QNetworkAccessFtpBackend::open(), QHttpNetworkConnectionChannel::sendRequest(), setEncodedUserName(), and setUserName().

4668 {
4669  if (!d) return QString();
4670 
4671  QMutexLocker lock(&d->mutex);
4673 
4674  d->userInfo(); // causes the unencoded form to be set
4675  return d->userName;
4676 }
void parse(ParseOptions parseOptions=ParseAndSet) const
Definition: qurl.cpp:3852
#define QURL_HASFLAG(a, b)
Definition: qurl.cpp:278
The QString class provides a Unicode character string.
Definition: qstring.h:83
int stateFlags
Definition: qurl.cpp:387
QString userInfo(QUrl::FormattingOptions options=QUrl::None) const
Definition: qurl.cpp:3673
QUrlPrivate * d
Definition: qurl.h:279
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QMutex mutex
Definition: qurl.cpp:394
QString userName
Definition: qurl.cpp:357

Friends and Related Functions

◆ operator<<()

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

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

See also
Format of the QDataStream operators

Definition at line 6757 of file qurl.cpp.

Referenced by operator<<().

6758 {
6759  QByteArray u = url.toEncoded();
6760  out << u;
6761  return out;
6762 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
quint16 u
QByteArray toEncoded(FormattingOptions options=None) const
Returns the encoded representation of the URL if it&#39;s valid; otherwise an empty QByteArray is returne...
Definition: qurl.cpp:5949

◆ operator>>()

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

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

See also
Format of the QDataStream operators

Definition at line 6774 of file qurl.cpp.

6775 {
6776  QByteArray u;
6777  in >> u;
6778  url = QUrl::fromEncoded(u);
6779  return in;
6780 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
quint16 u
static QUrl fromEncoded(const QByteArray &url)
Parses input and returns the corresponding QUrl.
Definition: qurl.cpp:5964

◆ qHash()

uint qHash ( const QUrl url)
related
Since
4.7

Computes a hash key from the normalized version of url.

Definition at line 285 of file qurl.h.

Referenced by containsTLDEntry(), getLock(), and qHash().

286 {
287  return qHash(url.toEncoded(QUrl::FormattingOption(0x100)));
288 }
FormattingOption
The formatting options define how the URL is formatted when written out as text.
Definition: qurl.h:70
QByteArray toEncoded(FormattingOptions options=None) const
Returns the encoded representation of the URL if it&#39;s valid; otherwise an empty QByteArray is returne...
Definition: qurl.cpp:5949
uint qHash(const QUrl &url)
Definition: qurl.h:285

Properties

◆ d

QUrlPrivate* QUrl::d
private

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