Qt:Документация 4.3.2/q3url
Материал из Wiki.crossplatform.ru
Внимание: Актуальная версия перевода документации находится здесь |
__NOTOC__
Главная · Все классы · Основные классы · Классы по группам · Модули · Функции |
[править] Q3Url Class Reference
[ Qt3Support module]
The Q3Url class provides a URL parser and simplifies working with URLs. Далее...
#include <Q3Url>
This class is part of the Qt 3 support library. It is provided to keep old source code working. Мы настоятельно не рекомендуем использовать этот класс в новом коде. See Porting to Qt 4 for more information.
Inherited by Q3UrlOperator.
[править] Открытые функции
- Q3Url ()
- Q3Url ( const QString & url )
- Q3Url ( const Q3Url & url )
- Q3Url ( const Q3Url & url, const QString & relUrl, bool checkSlash = false )
- virtual ~Q3Url ()
- virtual void addPath ( const QString & pa )
- virtual bool cdUp ()
- QString dirPath () const
- QString encodedPathAndQuery ()
- QString fileName () const
- bool hasHost () const
- bool hasPassword () const
- bool hasPath () const
- bool hasPort () const
- bool hasRef () const
- bool hasUser () const
- QString host () const
- bool isLocalFile () const
- bool isValid () const
- QString password () const
- QString path ( bool correct = true ) const
- int port () const
- QString protocol () const
- QString query () const
- QString ref () const
- virtual void setEncodedPathAndQuery ( const QString & pathAndQuery )
- virtual void setFileName ( const QString & name )
- virtual void setHost ( const QString & host )
- virtual void setPassword ( const QString & pass )
- virtual void setPath ( const QString & path )
- virtual void setPort ( int port )
- virtual void setProtocol ( const QString & protocol )
- virtual void setQuery ( const QString & txt )
- virtual void setRef ( const QString & txt )
- virtual void setUser ( const QString & user )
- virtual QString toString ( bool encodedPath = false, bool forcePrependProtocol = true ) const
- QString user () const
- operator QString () const
- Q3Url & operator= ( const Q3Url & url )
- Q3Url & operator= ( const QString & url )
- bool operator== ( const Q3Url & url ) const
- bool operator== ( const QString & url ) const
[править] Статические открытые члены
- void decode ( QString & url )
- void encode ( QString & url )
- bool isRelativeUrl ( const QString & url )
[править] Защищенные функции
[править] Подробное описание
The Q3Url class provides a URL parser and simplifies working with URLs.
The Q3Url class is provided for simple work with URLs. It can parse, decode, encode, etc.
Q3Url works with the decoded path and encoded query in turn.
Пример:
http://www.trolltech.com:80/cgi-bin/test%20me.pl?cmd=Hello%20you
Функция | Returns |
---|---|
protocol() | "http" |
host() | "www.trolltech.com" |
port() | 80 |
path() | "/cgi-bin/test me.pl" |
fileName() | "test me.pl" |
query() | "cmd=Hello%20you" |
Пример:
http://doc.trolltech.com/qdockarea.html#lines
Функция | Returns |
---|---|
protocol() | "http" |
host() | "doc.trolltech.com" |
fileName() | "qdockarea.html" |
ref() | "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.
Q3Url is normally used like this:
Q3Url url( "http://www.trolltech.com" ); // or Q3Url 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 Q3Urls and QStrings, Q3Url implements the necessary cast and assignment operators so you can do following:
Q3Url url( "http://www.trolltech.com" ); QString s = url; // or QString s( "http://www.trolltech.com" ); Q3Url 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 Q3UrlOperator.
See also Q3UrlOperator.
[править] Описание функций-членов
[править] Q3Url::Q3Url ()
Constructs an empty URL that is invalid.
[править] Q3Url::Q3Url ( const QString & url )
Constructs a URL by parsing the string url.
If you pass a string like "/home/qt", the "file" protocol is assumed.
[править] Q3Url::Q3Url ( const Q3Url & url )
Copy constructor. Copies the data of url.
[править] Q3Url::Q3Url ( const Q3Url & 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
Q3Url 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,
Q3Url 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,
Q3Url 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.
[править] Q3Url::~Q3Url () [virtual]
Деструктор.
[править] void Q3Url::addPath ( const QString & pa ) [virtual]
Adds the path pa to the path of the URL.
See also setPath() and hasPath().
[править] bool Q3Url::cdUp () [virtual]
Changes the directory to one directory up. This function always returns true.
See also setPath().
[править] void Q3Url::decode ( QString & url ) [static]
Decodes the url in-place into UTF-8. For example
QString url = "http%3A//www%20trolltech%20com" Q3Url::decode( url ); // url is now "http://www.trolltech.com"
See also encode().
[править] QString Q3Url::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().
[править] void Q3Url::encode ( QString & url ) [static]
Encodes the url in-place into UTF-8. For example
QString url = http://www.trolltech.com Q3Url::encode( url ); // url is now "http%3A//www%20trolltech%20com"
See also decode().
[править] QString Q3Url::encodedPathAndQuery ()
Returns the encoded path and query.
See also setEncodedPathAndQuery() and decode().
[править] QString Q3Url::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().
[править] bool Q3Url::hasHost () const
Returns true if the URL contains a hostname; otherwise returns false.
See also setHost().
[править] bool Q3Url::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 Q3Url::hasPath () const
Returns true if the URL contains a path; otherwise returns false.
See also path() and setPath().
[править] bool Q3Url::hasPort () const
Returns true if the URL contains a port; otherwise returns false.
Смотрите также setPort().
[править] bool Q3Url::hasRef () const
Returns true if the URL has a reference; otherwise returns false.
See also setRef().
[править] bool Q3Url::hasUser () const
Returns true if the URL contains a username; otherwise returns false.
See also setUser() and setPassword().
[править] QString Q3Url::host () const
Returns the hostname of the URL.
See also setHost() and hasHost().
[править] bool Q3Url::isLocalFile () const
Returns true if the URL is a local file; otherwise returns false.
[править] bool Q3Url::isRelativeUrl ( const QString & url ) [static]
Returns true if url is relative; otherwise returns false.
[править] bool Q3Url::isValid () const
Returns true if the URL is valid; otherwise returns false. A URL is invalid if it cannot be parsed, for example.
[править] bool Q3Url::parse ( const QString & url ) [virtual protected]
Parses the url. Возвращает true, если всё прошло успешно; в противном случае возвращает false.
[править] QString Q3Url::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 Q3Url::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().
[править] int Q3Url::port () const
Returns the port of the URL or -1 if no port has been set.
Смотрите также setPort().
[править] QString Q3Url::protocol () const
Returns the protocol of the URL. Typically, "file", "http", "ftp", etc.
See also setProtocol().
[править] QString Q3Url::query () const
Returns the (encoded) query of the URL.
See also setQuery() and decode().
[править] QString Q3Url::ref () const
Returns the (encoded) reference of the URL.
See also setRef(), hasRef(), and decode().
[править] void Q3Url::reset () [virtual protected]
Resets all parts of the URL to their default values and invalidates it.
[править] void Q3Url::setEncodedPathAndQuery ( const QString & pathAndQuery ) [virtual]
Parses pathAndQuery for a path and query and sets those values. The whole string must be encoded.
See also encodedPathAndQuery() and encode().
[править] void Q3Url::setFileName ( const QString & 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 Q3Url::setHost ( const QString & host ) [virtual]
Sets the hostname of the URL to host.
See also host() and hasHost().
[править] void Q3Url::setPassword ( const QString & 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 Qt.
See also password() and setUser().
[править] void Q3Url::setPath ( const QString & path ) [virtual]
Sets the path of the URL to path.
See also path() and hasPath().
[править] void Q3Url::setPort ( int port ) [virtual]
Sets the port of the URL to port.
See also port().
[править] void Q3Url::setProtocol ( const QString & protocol ) [virtual]
Sets the protocol of the URL to protocol. Typically, "file", "http", "ftp", etc.
See also protocol().
[править] void Q3Url::setQuery ( const QString & txt ) [virtual]
Sets the query of the URL to txt. txt must be encoded.
See also query() and encode().
[править] void Q3Url::setRef ( const QString & txt ) [virtual]
Sets the reference of the URL to txt. txt must be encoded.
See also ref(), hasRef(), and encode().
[править] void Q3Url::setUser ( const QString & user ) [virtual]
Sets the username of the URL to user.
See also user() and setPassword().
[править] QString Q3Url::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().
[править] QString Q3Url::user () const
Returns the username of the URL.
See also setUser() and setPassword().
[править] Q3Url::operator QString () const
Composes a string version of the URL and returns it.
See also Q3Url::toString().
[править] Q3Url & Q3Url::operator= ( const Q3Url & url )
Assigns the data of url to this class.
[править] Q3Url & Q3Url::operator= ( const QString & url )
Эта перегруженная функция предоставлена для удобства.
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 Q3Url::operator== ( const Q3Url & url ) const
Compares this URL with url and returns true if they are equal; otherwise returns false.
[править] bool Q3Url::operator== ( const QString & url ) const
Эта перегруженная функция предоставлена для удобства.
Compares this URL with url. url is parsed first. Returns true if url is equal to this url; otherwise returns false.
Copyright © 2007 Trolltech | Trademarks | Qt 4.3.2
|