The TQUrl class provides a URL parser and simplifies working with URLs.
More...
#include <tqurl.h>
Inherited by TQUrlOperator.
List of all member functions.
Public Members
Static Public Members
Protected Members
- virtual void reset ()
- virtual bool parse ( const TQString & url )
Detailed Description
The TQUrl class provides a URL parser and simplifies working with URLs.
The TQUrl class is provided for simple work with URLs. It can
parse, decode, encode, etc.
TQUrl 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/ntqdockarea.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.
TQUrl is normally used like this:
TQUrl url( "http://www.trolltech.com" );
// or
TQUrl 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 TQUrls and TQStrings, TQUrl implements
the necessary cast and assignment operators so you can do
following:
TQUrl url( "http://www.trolltech.com" );
TQString s = url;
// or
TQString s( "http://www.trolltech.com" );
TQUrl 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
TQUrlOperator.
See also TQUrlOperator, Input/Output and Networking, and Miscellaneous Classes.
Member Function Documentation
TQUrl::TQUrl ()
Constructs an empty URL that is invalid.
TQUrl::TQUrl ( const TQString & url )
Constructs a URL by parsing the string url.
If you pass a string like "/home/qt", the "file" protocol is
assumed.
TQUrl::TQUrl ( const TQUrl & url )
Copy constructor. Copies the data of url.
TQUrl::TQUrl ( const TQUrl & url, const TQString & 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
TQUrl 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,
TQUrl 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,
TQUrl 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.
TQUrl::~TQUrl () [virtual]
Destructor.
void TQUrl::addPath ( const TQString & pa ) [virtual]
Adds the path pa to the path of the URL.
See also setPath() and hasPath().
bool TQUrl::cdUp () [virtual]
Changes the directory to one directory up.
See also setPath().
void TQUrl::decode ( TQString & url ) [static]
Decodes the url in-place into UTF-8. For example
TQString url = "http%3A//www%20trolltech%20com"
TQUrl::decode( url );
// url is now "http://www.trolltech.com"
See also encode().
TQString TQUrl::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 TQUrl::encode ( TQString & url ) [static]
Encodes the url in-place into UTF-8. For example
TQString url = http://www.trolltech.com
TQUrl::encode( url );
// url is now "http%3A//www%20trolltech%20com"
See also decode().
Example: network/archivesearch/archivedialog.ui.h.
TQString TQUrl::encodedPathAndQuery ()
Returns the encoded path and query.
See also decode().
TQString TQUrl::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 TQUrl::hasHost () const
Returns TRUE if the URL contains a hostname; otherwise returns
FALSE.
See also setHost().
bool TQUrl::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 TQt.
See also setPassword() and setUser().
bool TQUrl::hasPath () const
Returns TRUE if the URL contains a path; otherwise returns FALSE.
See also path() and setPath().
bool TQUrl::hasPort () const
Returns TRUE if the URL contains a port; otherwise returns FALSE.
See also setPort().
bool TQUrl::hasRef () const
Returns TRUE if the URL has a reference; otherwise returns FALSE.
See also setRef().
bool TQUrl::hasUser () const
Returns TRUE if the URL contains a username; otherwise returns
FALSE.
See also setUser() and setPassword().
TQString TQUrl::host () const
Returns the hostname of the URL.
See also setHost() and hasHost().
Example: network/archivesearch/archivedialog.ui.h.
bool TQUrl::isLocalFile () const
Returns TRUE if the URL is a local file; otherwise returns FALSE.
Example: tqdir/tqdir.cpp.
bool TQUrl::isRelativeUrl ( const TQString & url ) [static]
Returns TRUE if url is relative; otherwise returns FALSE.
bool TQUrl::isValid () const
Returns TRUE if the URL is valid; otherwise returns FALSE. A URL
is invalid if it cannot be parsed, for example.
TQUrl::operator TQString () const
Composes a string version of the URL and returns it.
See also TQUrl::toString().
TQUrl & TQUrl::operator= ( const TQUrl & url )
Assigns the data of url to this class.
TQUrl & TQUrl::operator= ( const TQString & 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 TQUrl::operator== ( const TQUrl & url ) const
Compares this URL with url and returns TRUE if they are equal;
otherwise returns FALSE.
bool TQUrl::operator== ( const TQString & 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 TQUrl::parse ( const TQString & url ) [virtual protected]
Parses the url.
TQString TQUrl::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 TQt.
See also setPassword() and setUser().
TQString TQUrl::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: tqdir/tqdir.cpp.
int TQUrl::port () const
Returns the port of the URL or -1 if no port has been set.
See also setPort().
TQString TQUrl::protocol () const
Returns the protocol of the URL. Typically, "file", "http", "ftp",
etc.
See also setProtocol().
TQString TQUrl::query () const
Returns the (encoded) query of the URL.
See also setQuery() and decode().
TQString TQUrl::ref () const
Returns the (encoded) reference of the URL.
See also setRef(), hasRef(), and decode().
void TQUrl::reset () [virtual protected]
Resets all parts of the URL to their default values and
invalidates it.
void TQUrl::setEncodedPathAndQuery ( const TQString & pathAndQuery ) [virtual]
Parses pathAndQuery for a path and query and sets those values.
The whole string must be encoded.
See also encode().
void TQUrl::setFileName ( const TQString & name ) [virtual]
Sets the file name of the URL to name. If this URL contains a
fileName(), the original file name is replaced by name.
See the documentation of fileName() for a more detailed discussion
of what is handled as file name and what is handled as a directory
path.
See also fileName().
void TQUrl::setHost ( const TQString & host ) [virtual]
Sets the hostname of the URL to host.
See also host() and hasHost().
void TQUrl::setPassword ( const TQString & pass ) [virtual]
Sets the password of the URL to pass.
Warning: Passwords passed in URLs are normally insecure; this
is due to the mechanism, not because of TQt.
See also password() and setUser().
void TQUrl::setPath ( const TQString & path ) [virtual]
Sets the path of the URL to path.
See also path() and hasPath().
void TQUrl::setPort ( int port ) [virtual]
Sets the port of the URL to port.
See also port().
void TQUrl::setProtocol ( const TQString & protocol ) [virtual]
Sets the protocol of the URL to protocol. Typically, "file",
"http", "ftp", etc.
See also protocol().
void TQUrl::setQuery ( const TQString & txt ) [virtual]
Sets the query of the URL to txt. txt must be encoded.
See also query() and encode().
void TQUrl::setRef ( const TQString & txt ) [virtual]
Sets the reference of the URL to txt. txt must be encoded.
See also ref(), hasRef(), and encode().
void TQUrl::setUser ( const TQString & user ) [virtual]
Sets the username of the URL to user.
See also user() and setPassword().
TQString TQUrl::toString ( bool encodedPath = FALSE, bool forcePrependProtocol = TRUE ) const [virtual]
Composes a string version of the URL and returns it. If encodedPath is TRUE the path in the returned string is encoded. If
forcePrependProtocol is TRUE and encodedPath looks like a
local filename, the "file:/" protocol is also prepended.
See also encode() and decode().
TQString TQUrl::user () const
Returns the username of the URL.
See also setUser() and setPassword().
This file is part of the TQt toolkit.
Copyright © 1995-2007
Trolltech. All Rights Reserved.