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  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

Q3NetworkProtocol Class Reference

The Q3NetworkProtocol class provides a common API for network protocols. More...

 #include <Q3NetworkProtocol>

This class is part of the Qt 3 support library. It is provided to keep old source code working. We strongly advise against using it in new code. See Porting to Qt 4 for more information.

Inherits: QObject.

Inherited by: Q3Ftp, Q3Http, and Q3LocalFs.

Public Types

enum ConnectionState { ConHostFound, ConConnected, ConClosed }
enum Error { NoError, ErrValid, ErrUnknownProtocol, ErrUnsupported, ..., ErrPermissionDenied }
enum Operation { OpListChildren, OpMkDir, OpRemove, OpRename, OpGet, OpPut }
enum State { StWaiting, StInProgress, StDone, StFailed, StStopped }

Public Functions

Q3NetworkProtocol ()
virtual ~Q3NetworkProtocol ()
virtual void addOperation ( Q3NetworkOperation * op )
bool autoDelete () const
virtual void clearOperationQueue ()
Q3NetworkOperation * operationInProgress () const
virtual void setAutoDelete ( bool b, int i = 10000 )
virtual void setUrl ( Q3UrlOperator * u )
virtual void stop ()
virtual int supportedOperations () const
Q3UrlOperator * url () const
  • 29 public functions inherited from QObject

Signals

void connectionStateChanged ( int state, const QString & data )
void createdDirectory ( const QUrlInfo & i, Q3NetworkOperation * op )
void data ( const QByteArray & data, Q3NetworkOperation * op )
void dataTransferProgress ( int bytesDone, int bytesTotal, Q3NetworkOperation * op )
void finished ( Q3NetworkOperation * op )
void itemChanged ( Q3NetworkOperation * op )
void newChild ( const QUrlInfo & i, Q3NetworkOperation * op )
void newChildren ( const Q3ValueList<QUrlInfo> & i, Q3NetworkOperation * op )
void removed ( Q3NetworkOperation * op )
void start ( Q3NetworkOperation * op )

Static Public Members

Q3NetworkProtocol * getNetworkProtocol ( const QString & protocol )
bool hasOnlyLocalFileSystem ()
void registerNetworkProtocol ( const QString & protocol, Q3NetworkProtocolFactoryBase * protocolFactory )
  • 5 static public members inherited from QObject

Protected Functions

virtual bool checkConnection ( Q3NetworkOperation * op )
virtual void operationGet ( Q3NetworkOperation * op )
virtual void operationListChildren ( Q3NetworkOperation * op )
virtual void operationMkDir ( Q3NetworkOperation * op )
virtual void operationPut ( Q3NetworkOperation * op )
virtual void operationRemove ( Q3NetworkOperation * op )
virtual void operationRename ( Q3NetworkOperation * op )
  • 7 protected functions inherited from QObject

Additional Inherited Members

  • 1 property inherited from QObject
  • 1 public slot inherited from QObject

Detailed Description

The Q3NetworkProtocol class provides a common API for network protocols.

This is a base class which should be used for network protocols implementations that can then be used in Qt (e.g. in the file dialog) together with the Q3UrlOperator.

The easiest way to implement a new network protocol is to reimplement the operation*() methods, e.g. operationGet(), etc. Only the supported operations should be reimplemented. To specify which operations are supported, also reimplement supportedOperations() and return an int that is OR'd together using the supported operations from the Q3NetworkProtocol::Operation enum.

When you implement a network protocol this way, it is important to emit the correct signals. Also, always emit the finished() signal when an operation is done (on success and on failure). Qt relies on correctly emitted finished() signals.

Member Type Documentation

enum Q3NetworkProtocol::ConnectionState

When the connection state of a network protocol changes it emits the signal connectionStateChanged(). The first argument is one of the following values:

ConstantValueDescription
Q3NetworkProtocol::ConHostFound0Host has been found.
Q3NetworkProtocol::ConConnected1Connection to the host has been established.
Q3NetworkProtocol::ConClosed2Connection has been closed.

enum Q3NetworkProtocol::Error

When an operation fails (finishes unsuccessfully), the Q3NetworkOperation of the operation returns an error code which has one of the following values:

ConstantValueDescription
Q3NetworkProtocol::NoError0No error occurred.
Q3NetworkProtocol::ErrValid1The URL you are operating on is not valid.
Q3NetworkProtocol::ErrUnknownProtocol2There is no protocol implementation available for the protocol of the URL you are operating on (e.g. if the protocol is http and no http implementation has been registered).
Q3NetworkProtocol::ErrUnsupported3The operation is not supported by the protocol.
Q3NetworkProtocol::ErrParse4The URL could not be parsed correctly.
Q3NetworkProtocol::ErrLoginIncorrect5You needed to login but the username or password is wrong.
Q3NetworkProtocol::ErrHostNotFound6The specified host (in the URL) couldn't be found.
Q3NetworkProtocol::ErrListChildren7An error occurred while listing the children (files).
Q3NetworkProtocol::ErrMkDir?An error occurred when creating a directory.
Q3NetworkProtocol::ErrRemove?An error occurred when removing a child (file).
Q3NetworkProtocol::ErrRename?An error occurred when renaming a child (file).
Q3NetworkProtocol::ErrGet?An error occurred while getting (retrieving) data.
Q3NetworkProtocol::ErrPut?An error occurred while putting (uploading) data.
Q3NetworkProtocol::ErrFileNotExisting?A file which is needed by the operation doesn't exist.
Q3NetworkProtocol::ErrPermissionDenied?Permission for doing the operation has been denied.

You should also use these error codes when implementing custom network protocols. If this is not possible, you can define your own error codes by using integer values that don't conflict with any of these values.

enum Q3NetworkProtocol::Operation

This enum lists the possible operations that a network protocol can support. supportedOperations() returns an int of these that is OR'd together. Also, the type() of a Q3NetworkOperation is always one of these values.

ConstantValueDescription
Q3NetworkProtocol::OpListChildren1List the children of a URL, e.g. of a directory.
Q3NetworkProtocol::OpMkDir2Create a directory.
Q3NetworkProtocol::OpRemove4Remove a child (e.g. a file).
Q3NetworkProtocol::OpRename8Rename a child (e.g. a file).
Q3NetworkProtocol::OpGet32Get data from a location.
Q3NetworkProtocol::OpPut64Put data to a location.

enum Q3NetworkProtocol::State

This enum contains the state that a Q3NetworkOperation can have.

ConstantValueDescription
Q3NetworkProtocol::StWaiting0The operation is in the Q3NetworkProtocol's queue waiting to be prcessed.
Q3NetworkProtocol::StInProgress1The operation is being processed.
Q3NetworkProtocol::StDone2The operation has been processed successfully.
Q3NetworkProtocol::StFailed3The operation has been processed but an error occurred.
Q3NetworkProtocol::StStopped4The operation has been processed but has been stopped before it finished, and is waiting to be processed.

Member Function Documentation

Q3NetworkProtocol::Q3NetworkProtocol ()

Constructor of the network protocol base class. Does some initialization and connecting of signals and slots.

Q3NetworkProtocol::~Q3NetworkProtocol () [virtual]

Destructor.

void Q3NetworkProtocol::addOperation ( Q3NetworkOperation * op ) [virtual]

Adds the operation op to the operation queue. The operation will be processed as soon as possible. This method returns immediately.

bool Q3NetworkProtocol::autoDelete () const

Returns true if auto-deleting is enabled; otherwise returns false.

See also Q3NetworkProtocol::setAutoDelete().

bool Q3NetworkProtocol::checkConnection ( Q3NetworkOperation * op ) [virtual protected]

For processing operations the network protocol base class calls this method quite often. This should be reimplemented by new network protocols. It should return true if the connection is OK (open); otherwise it should return false. If the connection is not open the protocol should open it.

If the connection can't be opened (e.g. because you already tried but the host couldn't be found), set the state of op to Q3NetworkProtocol::StFailed and emit the finished() signal with this Q3NetworkOperation as argument.

op is the operation that needs an open connection.

void Q3NetworkProtocol::clearOperationQueue () [virtual]

Clears the operation queue.

void Q3NetworkProtocol::connectionStateChanged ( int state, const QString & data ) [signal]

This signal is emitted whenever the state of the connection of the network protocol is changed. state describes the new state, which is one of, ConHostFound, ConConnected or ConClosed. data is a message text.

void Q3NetworkProtocol::createdDirectory ( const QUrlInfo & i, Q3NetworkOperation * op ) [signal]

This signal is emitted when mkdir() has been successful and the directory has been created. i holds the information about the new directory. op is the pointer to the operation object which contains all the information about the operation, including the state, etc. Using op->arg( 0 ), you can get the file name of the new directory.

When a protocol emits this signal, Q3NetworkProtocol is smart enough to let the Q3UrlOperator, which is used by the network protocol, emit its corresponding signal.

void Q3NetworkProtocol::data ( const QByteArray & data, Q3NetworkOperation * op ) [signal]

This signal is emitted when new data has been received after calling get() or put(). op holds the name of the file from which data is retrieved or uploaded in its first argument, and the (raw) data in its second argument. You can get them with op->arg( 0 ) and op->rawArg( 1 ). op is the pointer to the operation object, which contains all the information about the operation, including the state, etc.

When a protocol emits this signal, Q3NetworkProtocol is smart enough to let the Q3UrlOperator (which is used by the network protocol) emit its corresponding signal.

void Q3NetworkProtocol::dataTransferProgress ( int bytesDone, int bytesTotal, Q3NetworkOperation * op ) [signal]

This signal is emitted during the transfer of data (using put() or get()). bytesDone is how many bytes of bytesTotal have been transferred. bytesTotal may be -1, which means that the total number of bytes is not known. op is the pointer to the operation object which contains all the information about the operation, including the state, etc.

When a protocol emits this signal, Q3NetworkProtocol is smart enough to let the Q3UrlOperator, which is used by the network protocol, emit its corresponding signal.

void Q3NetworkProtocol::finished ( Q3NetworkOperation * op ) [signal]

This signal is emitted when an operation finishes. This signal is always emitted, for both success and failure. op is the pointer to the operation object which contains all the information about the operation, including the state, etc. Check the state and error code of the operation object to determine whether or not the operation was successful.

When a protocol emits this signal, Q3NetworkProtocol is smart enough to let the Q3UrlOperator, which is used by the network protocol, emit its corresponding signal.

Q3NetworkProtocol * Q3NetworkProtocol::getNetworkProtocol ( const QString & protocol ) [static]

Static method to get a new instance of the network protocol protocol. For example, if you need to do some FTP operations, do the following:

 Q3Ftp *ftp = Q3NetworkProtocol::getNetworkProtocol( "ftp" );

This returns a pointer to a new instance of an ftp implementation or null if no protocol for ftp was registered. The ownership of the pointer is transferred to you, so you must delete it if you don't need it anymore.

Normally you should not work directly with network protocols, so you will not need to call this method yourself. Instead, use Q3UrlOperator, which makes working with network protocols much more convenient.

See also Q3UrlOperator.

bool Q3NetworkProtocol::hasOnlyLocalFileSystem () [static]

Returns true if the only protocol registered is for working on the local filesystem; returns false if other network protocols are also registered.

void Q3NetworkProtocol::itemChanged ( Q3NetworkOperation * op ) [signal]

This signal is emitted whenever a file which is a child of this URL has been changed, e.g. by successfully calling rename(). op holds the original and the new file names in the first and second arguments, accessible with op->arg( 0 ) and op->arg( 1 ) respectively. op is the pointer to the operation object which contains all the information about the operation, including the state, etc.

When a protocol emits this signal, Q3NetworkProtocol is smart enough to let the Q3UrlOperator, which is used by the network protocol, emit its corresponding signal.

void Q3NetworkProtocol::newChild ( const QUrlInfo & i, Q3NetworkOperation * op ) [signal]

This signal is emitted if a new child (file) has been read. Q3NetworkProtocol automatically connects it to a slot which creates a list of QUrlInfo objects (with just one QUrlInfo i) and emits the newChildren() signal with this list. op is the pointer to the operation object which contains all the information about the operation that has finished, including the state, etc.

This is just a convenience signal useful for implementing your own network protocol. In all other cases connect to the newChildren() signal with its list of QUrlInfo objects.

void Q3NetworkProtocol::newChildren ( const Q3ValueList<QUrlInfo> & i, Q3NetworkOperation * op ) [signal]

This signal is emitted after listChildren() was called and new children (files) have been read from the list of files. i holds the information about the new children. op is the pointer to the operation object which contains all the information about the operation, including the state, etc.

When a protocol emits this signal, Q3NetworkProtocol is smart enough to let the Q3UrlOperator, which is used by the network protocol, emit its corresponding signal.

When implementing your own network protocol and reading children, you usually don't read one child at once, but rather a list of them. That's why this signal takes a list of QUrlInfo objects. If you prefer to read just one child at a time you can use the convenience signal newChild(), which takes a single QUrlInfo object.

void Q3NetworkProtocol::operationGet ( Q3NetworkOperation * op ) [virtual protected]

When implementing a new network protocol, this method should be reimplemented if the protocol supports getting data; this method should then process the Q3NetworkOperation.

op is the pointer to the operation object which contains all the information on the operation that has finished, including the state, etc.

Q3NetworkOperation * Q3NetworkProtocol::operationInProgress () const

Returns the operation, which is being processed, or 0 of no operation is being processed at the moment.

void Q3NetworkProtocol::operationListChildren ( Q3NetworkOperation * op ) [virtual protected]

When implementing a new network protocol, this method should be reimplemented if the protocol supports listing children (files); this method should then process this Q3NetworkOperation.

op is the pointer to the operation object which contains all the information on the operation that has finished, including the state, etc.

void Q3NetworkProtocol::operationMkDir ( Q3NetworkOperation * op ) [virtual protected]

When implementing a new network protocol, this method should be reimplemented if the protocol supports making directories; this method should then process this Q3NetworkOperation.

op is the pointer to the operation object which contains all the information on the operation that has finished, including the state, etc.

void Q3NetworkProtocol::operationPut ( Q3NetworkOperation * op ) [virtual protected]

When implementing a new network protocol, this method should be reimplemented if the protocol supports putting (uploading) data; this method should then process the Q3NetworkOperation.

op is the pointer to the operation object which contains all the information on the operation that has finished, including the state, etc.

void Q3NetworkProtocol::operationRemove ( Q3NetworkOperation * op ) [virtual protected]

When implementing a new network protocol, this method should be reimplemented if the protocol supports removing children (files); this method should then process this Q3NetworkOperation.

op is the pointer to the operation object which contains all the information on the operation that has finished, including the state, etc.

void Q3NetworkProtocol::operationRename ( Q3NetworkOperation * op ) [virtual protected]

When implementing a new network protocol, this method should be reimplemented if the protocol supports renaming children (files); this method should then process this Q3NetworkOperation.

op is the pointer to the operation object which contains all the information on the operation that has finished, including the state, etc.

void Q3NetworkProtocol::registerNetworkProtocol ( const QString & protocol, Q3NetworkProtocolFactoryBase * protocolFactory ) [static]

Static method to register a network protocol for Qt. For example, if you have an implementation of NNTP (called Nntp) which is derived from Q3NetworkProtocol, call:

 Q3NetworkProtocol::registerNetworkProtocol( "nntp", new Q3NetworkProtocolFactory<Nntp> );

after which your implementation is registered for future nntp operations.

The name of the protocol is given in protocol and a pointer to the protocol factory is given in protocolFactory.

void Q3NetworkProtocol::removed ( Q3NetworkOperation * op ) [signal]

This signal is emitted when remove() has been succesiisful and the file has been removed. op holds the file name of the removed file in the first argument, accessible with op->arg( 0 ). op is the pointer to the operation object which contains all the information about the operation, including the state, etc.

When a protocol emits this signal, Q3NetworkProtocol is smart enough to let the Q3UrlOperator, which is used by the network protocol, emit its corresponding signal.

void Q3NetworkProtocol::setAutoDelete ( bool b, int i = 10000 ) [virtual]

Because it's sometimes hard to take care of removing network protocol instances, Q3NetworkProtocol provides an auto-delete mechanism. If you set b to true, the network protocol instance is removed after it has been inactive for i milliseconds (i.e. i milliseconds after the last operation has been processed). If you set b to false the auto-delete mechanism is switched off.

If you switch on auto-delete, the Q3NetworkProtocol also deletes its Q3UrlOperator.

See also autoDelete().

void Q3NetworkProtocol::setUrl ( Q3UrlOperator * u ) [virtual]

Sets the Q3UrlOperator, on which the protocol works, to u.

See also url() and Q3UrlOperator.

void Q3NetworkProtocol::start ( Q3NetworkOperation * op ) [signal]

Some operations (such as listChildren()) emit this signal when they start processing the operation. op is the pointer to the operation object which contains all the information about the operation, including the state, etc.

When a protocol emits this signal, Q3NetworkProtocol is smart enough to let the Q3UrlOperator, which is used by the network protocol, emit its corresponding signal.

void Q3NetworkProtocol::stop () [virtual]

Stops the current operation that is being processed and clears all waiting operations.

int Q3NetworkProtocol::supportedOperations () const [virtual]

Returns an int that is OR'd together using the enum values of Q3NetworkProtocol::Operation, which describes which operations are supported by the network protocol. Should be reimplemented by new network protocols.

Q3UrlOperator * Q3NetworkProtocol::url () const

Returns the Q3UrlOperator on which the protocol works.

See also setUrl().

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 88
  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 ? 39
  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 6
Page suivante

Le blog Digia au hasard

Logo

Créer des applications avec un style Metro avec Qt, exemples en QML et C++, un article de Digia Qt traduit par Thibaut Cuvelier

Le blog Digia est l'endroit privilégié pour la communication sur l'édition commerciale de Qt, où des réponses publiques sont apportées aux questions les plus posées au support. 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 4.7-snapshot
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