Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Classes  ·  Annotées  ·  Hiérarchie  ·  Fonctions  ·  Structure  · 

QUrl Class Reference


The QUrl class provides mainly an URL parser and simplifies working with URLs. More...

#include <qurl.h>

Inherited by QUrlOperator.

List of all member functions.

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 & user ) 
  • bool hasHost () const
  • int port () const
  • virtual void setPort ( int port ) 
  • QString path ( bool correct = TRUE ) const
  • virtual void setPath ( const QString & path ) 
  • bool hasPath () const
  • virtual void setEncodedPathAndQuery ( const QString & enc ) 
  • 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 & path ) 
  • virtual void setFileName ( const QString & txt ) 
  • 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 ) 

Detailed Description

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

The QUrl class is provided for a easy working with URLs. It does all parsing, decoding, encoding and so on.

Mention that URL has some restrictions regarding the path encoding. URL works intern with the decoded path and and encoded query. For example in

http://localhost/cgi-bin/test%20me.pl?cmd=Hello%20you

would result in a decoded path "/cgi-bin/test me.pl" and in the encoded query "cmd=Hello%20you". Since path is internally always encoded you may NOT use "%00" in the path while this is ok for the query.

QUrl is normally used like that:

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

Then you can access the parts of the URL, change them and do some more stuff.

To allow easy working with QUrl and QString together, QUrl implements the needed cast and assign operators. So you can do following:

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

If you want to use an URL to work on a hierarchical structures (e.g. locally or remote filesystem) the class QUrlOperator, which is derived fro QUrl, may be interesting for you.

See also QUrlOperator.


Member Function Documentation

QUrl::QUrl ()

Constructs an empty URL which, is invalid.

QUrl::QUrl ( const QString & url )

Constructs an URL using url and parses this string.

You can pass strings like "/home/qt", in this case the protocol "file" 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 base (context) and relUrl as relative URL to url. If relUrl is not relative, relUrl is taken as new URL.

For example, the path of

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

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

And

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

will result in a new URL, "ftp://ftp.trolltech.com/usr/local",

And

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

will result in a new URL, with "/usr/local" as path and "file" as 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 that the constructor handles the last part of the path as filename, if there is no slash at the end, and let it replace by the filename of relUrl (if it contains one), set checkSlash to TRUE.

QUrl::~QUrl () [virtual]

Destructor.

QUrl::operator QString () const

Composes a string of the URL and returns it.

See also QUrl::toString().

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

Adds the path pa to the path of the URL.

bool QUrl::cdUp () [virtual]

Goes one directory up.

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

Decodes the string url.

QString QUrl::dirPath () const

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

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

Encodes the string url.

QString QUrl::encodedPathAndQuery ()

Returns the encoded path plus the query (encoded too).

QString QUrl::fileName () const

Returns the filename 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 handled as filename. If the path has a slash at the end, an empty string is returned here.

bool QUrl::hasHost () const

Returns TRUE, if the URL contains a hostname, else FALSE;.

bool QUrl::hasPassword () const

Returns TRUE, if the URL contains a password, else FALSE;.

bool QUrl::hasPath () const

Returns TRUE, if the URL contains a path, else FALSE.

bool QUrl::hasRef () const

Returns TRUE, if the URL has a reference, else it returns FALSE.

bool QUrl::hasUser () const

Returns TRUE, if the URL contains an username, else FALSE;.

QString QUrl::host () const

Returns the hostname of the URL.

bool QUrl::isLocalFile () const

Returns TRUE, if the URL is a local file, else it returns FALSE;.

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

Returns TRUE, if url is relative, else it returns FALSE.

bool QUrl::isValid () const

Returns TRUE if the URL is valid, else FALSE. An URL is e.g. invalid if there was a parse error.

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

Assign operator. Parses url and assigns the resulting data to this class.

You can pass strings like "/home/qt", in this case the protocol "file" is assumed.

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

Assign operator. Assigns the data of url to this class.

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

Compares this URL with url. url is parsed first. Returns TRUE if url is equal to this url, else FALSE:.

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

Compares this URL with url and returns TRUE if they are equal, else FALSE.

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

Parses the url.

QString QUrl::password () const

Returns the password of the URL.

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 few slashes, cleans things like "/../..", etc). Else exactly the path which was parsed or set is returned.

int QUrl::port () const

Returns the port of the URL.

QString QUrl::protocol () const

Returns the protocol of the URL. It is something like "file" or "ftp".

QString QUrl::query () const

Returns the query (encoded) of the URL.

QString QUrl::ref () const

Returns the reference (encoded) of the URL.

void QUrl::reset () [virtual protected]

Resets all values if the URL to its default values and invalidates it.

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

Sets path and query. Both have to be encoded.

void QUrl::setFileName ( const QString & name ) [virtual]

Sets the filename of the URL to name. If this url contains a fileName(), this is replaced by name. See the documentation of fileName() for a more detail discussion, about what is handled as file name and what as directory path.

void QUrl::setHost ( const QString & host ) [virtual]

Sets the hostname of the URL.

void QUrl::setPassword ( const QString & pass ) [virtual]

Sets the password of the URL.

void QUrl::setPath ( const QString & path ) [virtual]

Sets the path or the URL.

void QUrl::setPort ( int port ) [virtual]

Sets the port of the URL.

void QUrl::setProtocol ( const QString & protocol ) [virtual]

Sets the protocol of the URL. This could be e.g. "file", "ftp", or something similar.

void QUrl::setQuery ( const QString & txt ) [virtual]

Sets the query of the URL. Must be encoded.

void QUrl::setRef ( const QString & txt ) [virtual]

Sets the reference of the URL. Must be encoded.

void QUrl::setUser ( const QString & user ) [virtual]

Sets the username of the URL.

QString QUrl::toString ( bool encodedPath = FALSE, bool forcePrependProtocol = TRUE ) const [virtual]

Composes a string of the URL and returns it. If encodedPath is TRUE, the path in the returned string will be encoded. If forcePrependProtocol is TRUE, the protocol (file:/) is also prepended to local filenames, else no protocol is prepended for local filenames.

QString QUrl::user () const

Returns the username of the URL.


Search the documentation, FAQ, qt-interest archive and more (uses www.trolltech.com):


This file is part of the Qt toolkit, copyright © 1995-2005 Trolltech, all rights reserved.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 94
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 42
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 7
Page suivante

Le Qt Labs au hasard

Logo

Vue d'ensemble

Les Qt Labs sont les laboratoires des développeurs de Qt, où ils peuvent partager des impressions sur le framework, son utilisation, ce que pourrait être son futur. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 2.3
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web