QUrl(3qt)

πŸ“¦ version 3.3.8b, in fedora 43, fedora 44

πŸ’– QUrl πŸ’–

okay bestie, welcome to the QUrl page from the 3qt manual ✨ this is part 1 of 2, so don't you dare close the tab β€” there's more coming πŸ’…


🌸 NAME 🌸

QUrl β€” URL parser and simplifies working with URLs


✨ SYNOPSIS ✨

#include <qurl.h>

Inherited by QUrlOperator.

πŸŽ€ Public Members πŸŽ€

QUrl ()
QUrl ( const QString & url )
QUrl ( const QUrl & url )
QUrl ( const QUrl & url, const QString & relUrl, bool checkSlash = FALSE
    )
virtual ~QUrl ()
QString protocol () const
virtual void setProtocol ( const QString & protocol )
QString user () const
virtual void setUser ( const QString & user )
bool hasUser () const
QString password () const
virtual void setPassword ( const QString & pass )
bool hasPassword () const
QString host () const
virtual void setHost ( const QString & host )
bool hasHost () const
int port () const
virtual void setPort ( int port )
bool hasPort () const
QString path ( bool correct = TRUE ) const
virtual void setPath ( const QString & path )
bool hasPath () const
virtual void setEncodedPathAndQuery ( const QString & pathAndQuery )
QString encodedPathAndQuery ()
virtual void setQuery ( const QString & txt )
QString query () const
QString ref () const
virtual void setRef ( const QString & txt )
bool hasRef () const
bool isValid () const
bool isLocalFile () const
virtual void addPath ( const QString & pa )
virtual void setFileName ( const QString & name )
QString fileName () const
QString dirPath () const
QUrl & operator= ( const QUrl & url )
QUrl & operator= ( const QString & url )
bool operator== ( const QUrl & url ) const
bool operator== ( const QString & url ) const
operator QString () const
virtual QString toString ( bool encodedPath = FALSE, bool
    forcePrependProtocol = TRUE ) const
virtual bool cdUp ()

🌈 Static Public Members 🌈

void decode ( QString & url )
void encode ( QString & url )
bool isRelativeUrl ( const QString & url )

πŸ¦‹ Protected Members πŸ¦‹

virtual void reset ()
virtual bool parse ( const QString & url )

πŸ‘‘ DESCRIPTION πŸ‘‘

The QUrl class provides a URL parser and simplifies working with URLs.

So like, QUrl exists for simple work with URLs, fr fr. It can parse, decode, encode, etc. πŸ’…

QUrl works with the decoded path and encoded query in turn.

Example:

http://www.trolltech.com:80/cgi-bin/test%20me.pl?cmd=Hello%20you

Example:

http://doc.trolltech.com/qdockarea.html#lines

The individual parts of a URL can be set with setProtocol(), setHost(), setPort(), setPath(), setFileName(), setRef() and setQuery(). A URL could contain, for example, an ftp address which requires a user name and password; these can be set with setUser() and setPassword(). 🫢

Because path is always encoded internally you must not use "%00" in the path, although this is okay (but not recommended) for the query. 🚨

QUrl is normally used like this:

QUrl url( "http://www.trolltech.com" );
// or
QUrl url( "file:/home/myself/Mail", "Inbox" );

You can then access and manipulate the various parts of the URL. ✨

To make it easy to work with QUrls and QStrings, QUrl implements the necessary cast and assignment operators so you can do following:

QUrl url( "http://www.trolltech.com" );
QString s = url;
// or
QString s( "http://www.trolltech.com" );
QUrl url( s );

Use the static functions, encode() and decode() to encode or decode a URL in a string. (They operate on the string in-place.) The isRelativeUrl() static function returns TRUE if the given string is a relative URL.

If you want to use a URL to work on a hierarchical structure (e.g. a local or remote filesystem), you might want to use the subclass QUrlOperator. πŸ‘‘

See also QUrlOperator, Input/Output and Networking, and Miscellaneous Classes.


πŸ’œ MEMBER FUNCTION DOCUMENTATION πŸ’œ

🌟 QUrl::QUrl ()

Constructs an empty URL that is invalid. (ngl, it's giving nothing-but-potential πŸ’€)

🌟 QUrl::QUrl ( const QString & url )

Constructs a URL by parsing the string url.

If you pass a string like "/home/qt", the "file" protocol is assumed. πŸŽ€

🌟 QUrl::QUrl ( const QUrl & url )

Copy constructor. Copies the data of url.

🌟 QUrl::QUrl ( const QUrl & url, const QString & relUrl, bool checkSlash = FALSE )

Constructs an URL taking url as the base (context) and relUrl as a relative URL to url. If relUrl is not relative, relUrl is taken as the new URL.

For example, the path of

QUrl url( "ftp://ftp.trolltech.com/qt/source", "qt-2.1.0.tar.gz" );

will be "/qt/srource/qt-2.1.0.tar.gz".

On the other hand,

QUrl url( "ftp://ftp.trolltech.com/qt/source", "/usr/local" );

will result in a new URL, "ftp://ftp.trolltech.com/usr/local", because "/usr/local" isn't relative.

Similarly,

QUrl url( "ftp://ftp.trolltech.com/qt/source", "file:/usr/local" );

will result in a new URL, with "/usr/local" as the path and "file" as the protocol.

Normally it is expected that the path of url points to a directory, even if the path has no slash at the end. But if you want the constructor to handle the last part of the path as a file name if there is no slash at the end, and to let it be replaced by the file name of relUrl (if it contains one), set checkSlash to TRUE. πŸ¦‹

🌟 QUrl::~QUrl () [virtual]

Destructor. bye bestie πŸ‘‹

🌟 void QUrl::addPath ( const QString & pa ) [virtual]

Adds the path pa to the path of the URL.

See also setPath() and hasPath().

🌟 bool QUrl::cdUp () [virtual]

Changes the directory to one directory up. ⬆️

See also setPath().

🌟 void QUrl::decode ( QString & url ) [static]

Decodes the url in-place into UTF-8. For example

QString url = "http%3A//www%20trolltech%20com"
QUrl::decode( url );
// url is now "http://www.trolltech.com"

See also encode().

🌟 QString QUrl::dirPath () const

Returns the directory path of the URL. This is the part of the path of the URL without the fileName(). See the documentation of fileName() for a discussion of what is handled as file name and what is handled as directory path. πŸ“

See also setPath() and hasPath().

Example: network/networkprotocol/nntp.cpp.

🌟 void QUrl::encode ( QString & url ) [static]

Encodes the url in-place into UTF-8. For example

QString url = http://www.trolltech.com
QUrl::encode( url );
// url is now "http%3A//www%20trolltech%20com"

See also decode().

Example: network/archivesearch/archivedialog.ui.h.

🌟 QString QUrl::encodedPathAndQuery ()

Returns the encoded path and query. πŸ”₯

See also decode().

🌟 QString QUrl::fileName () const

Returns the file name of the URL. If the path of the URL doesn't have a slash at the end, the part between the last slash and the end of the path string is considered to be the file name. If the path has a slash at the end, an empty string is returned here.

See also setFileName().

Example: network/networkprotocol/nntp.cpp.

🌟 bool QUrl::hasHost () const

Returns TRUE if the URL contains a hostname; otherwise returns FALSE.

See also setHost().

🌟 bool QUrl::hasPassword () const

Returns TRUE if the URL contains a password; otherwise returns FALSE.

Warning: Passwords passed in URLs are normally insecure; this is due to the mechanism, not because of Qt. 🚨

See also setPassword() and setUser().

🌟 bool QUrl::hasPath () const

Returns TRUE if the URL contains a path; otherwise returns FALSE.

See also path() and setPath().

🌟 bool QUrl::hasPort () const

Returns TRUE if the URL contains a port; otherwise returns FALSE.

See also setPort().

🌟 bool QUrl::hasRef () const

Returns TRUE if the URL has a reference; otherwise returns FALSE.

See also setRef().

🌟 bool QUrl::hasUser () const

Returns TRUE if the URL contains a username; otherwise returns FALSE.

See also setUser() and setPassword().

🌟 QString QUrl::host () const

Returns the hostname of the URL. πŸ’»

See also setHost() and hasHost().

Example: network/archivesearch/archivedialog.ui.h.

🌟 bool QUrl::isLocalFile () const

Returns TRUE if the URL is a local file; otherwise returns FALSE.

Example: qdir/qdir.cpp.

🌟 bool QUrl::isRelativeUrl ( const QString & url ) [static]

Returns TRUE if url is relative; otherwise returns FALSE.

🌟 bool QUrl::isValid () const

Returns TRUE if the URL is valid; otherwise returns FALSE. A URL is invalid if it cannot be parsed, for example. πŸ™ˆ

🌟 QUrl::operator QString () const

Composes a string version of the URL and returns it.

See also QUrl::toString().

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

Assigns the data of url to this class.

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

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Parses url and assigns the resulting data to this class.

If you pass a string like "/home/qt" the "file" protocol will be assumed.

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

Compares this URL with url and returns TRUE if they are equal; otherwise returns FALSE.

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

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Compares this URL with url. url is parsed first. Returns TRUE if url is equal to this url; otherwise returns FALSE.

🌟 bool QUrl::parse ( const QString & url ) [virtual protected]

Parses the url.

🌟 QString QUrl::password () const

Returns the password of the URL.

Warning: Passwords passed in URLs are normally insecure; this is due to the mechanism, not because of Qt. 🚨

See also setPassword() and setUser().

🌟 QString QUrl::path ( bool correct = TRUE ) const

Returns the path of the URL. If correct is TRUE, the path is cleaned (deals with too many or too few slashes, cleans things like "/../..", etc). Otherwise path() returns exactly the path that was parsed or set.

See also setPath() and hasPath().

Example: qdir/qdir.cpp.

🌟 int QUrl::port () const

Returns the port of the URL or -1 if no port has been set.

See also setPort().

🌟 QString QUrl::protocol () const

Returns the protocol of the URL. Typically, "file", "http", "ftp", etc.

See also setProtocol().

🌟 QString QUrl::query () const

Returns the (encoded) query of the URL.

See also setQuery() and decode().

🌟 QString QUrl::ref () const

Returns the (encoded) reference of the URL.

See also setRef(), hasRef(), and decode().

🌟 void QUrl::reset () [virtual protected]

Resets all parts of the URL to their default values and invalidates it. 🧼

🌟 void QUrl::setEncodedPathAndQuery ( const QString & pathAndQuery ) [virtual]

Parses pathAndQuery for a path and query and sets those values. The whole string must be encoded.

See also encode().


🌸 okay that's the end of part 1, bestie β€” don't go anywhere, part 2 is right behind it πŸ’–

  • void QUrl::setFileName ( const QString & name ) [virtual] β€” sets the file name of the URL to name, bestie. If this URL already has a fileName(), the original one gets replaced by name. πŸ’«

Wanna know what counts as a "file name" vs. a "directory path" in this economy? The docs for fileName() break it all down in detail, so go read that.

See also fileName().


  • void QUrl::setHost ( const QString & host ) [virtual] β€” sets the hostname of the URL to host. boom, done. 🏠

See also host() and hasHost().

  • void QUrl::setPassword ( const QString & pass ) [virtual] β€” sets the password of the URL to pass. πŸ”
⚠️ Warning: passwords passed in URLs are normally insecure β€” and that's the mechanism's fault, not Qt's. Not us. Not our problem. But also very much something you should know, fr fr.

See also password() and setUser().

  • void QUrl::setPath ( const QString & path ) [virtual] β€” sets the path of the URL to path. πŸ›£οΈ

See also path() and hasPath().

  • void QUrl::setPort ( int port ) [virtual] β€” sets the port of the URL to port. πŸšͺ

See also port().

  • void QUrl::setProtocol ( const QString & protocol ) [virtual] β€” sets the protocol of the URL to protocol. Typically like "file", " http", "ftp", etc. πŸ’…

See also protocol().

  • void QUrl::setQuery ( const QString & txt ) [virtual] β€” sets the query of the URL to txt. And listen β€” txt must be encoded, no skipping that step. ✨

See also query() and encode().

  • void QUrl::setRef ( const QString & txt ) [virtual] β€” sets the reference of the URL to txt. Same rule as above: txt must be encoded. πŸŽ€

See also ref(), hasRef(), and encode().

  • void QUrl::setUser ( const QString & user ) [virtual] β€” sets the username of the URL to user. πŸ‘€

See also user() and setPassword().


  • QString QUrl::toString ( bool encodedPath = FALSE, bool forcePrependProtocol = TRUE ) const [virtual] β€” composes a string version of the URL and hands it right back to you, like the little gift it is. 🎁
    • If encodedPath is TRUE, the path in the returned string is encoded. πŸ”’
    • If forcePrependProtocol is TRUE and encodedPath looks like a local filename, then the "file:/" protocol also gets prepended. πŸ“Ž

See also encode() and decode().

  • QString QUrl::user () const β€” returns the username of the URL. that's it, that's the whole vibe. 🌸

See also setUser() and setPassword().


πŸ’– SEE ALSO πŸ’–


Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement. πŸ‘‘


✨ AUTHOR ✨

Generated automatically from the source code. (yes, the robot wrote it. iconic of them honestly.) πŸ€–


πŸ’€ BUGS πŸ’€

Found a bug in Qt? Please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us help you. Thank you!! πŸ₯ΊπŸ«Ά (genuinely, we love a detailed bug report)

The definitive Qt documentation is provided in HTML format β€” it lives at $QTDIR/doc/html and you can read it with Qt Assistant or just a web browser. This man page is provided as a convenience for the people who prefer man pages, even though this format isn't officially supported by Trolltech. 🌈

If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qurl.3qt) and the Qt version (3.3.8). πŸ“


okay bestie that's the whole page πŸ’… shoutout to Trolltech AS for this one, dropped on 2 February 2007, and yeah it's the QUrl(3qt) page β€” go forth and parse those URLs, you absolute main character. πŸ’–πŸ¦‹βœ¨

πŸ“¦ where this page comes from