![]() |
| ||
Classes - Annotated - Tree - Functions - Home - Structure |
The QNetworkProtocol class provides a common API for network protocols. More...
#include <qnetworkprotocol.h>
Inherits QObject.
Inherited by QFtp, QHttp and QLocalFs.
This is a base class which should be used for implementations of network protocols that can then be used in Qt (e.g., in the filedialog) together with the QUrlOperator.
The easiest way to implement a new network protocol is to reimplement the operation[something]( QNetworkOperation * ) methods. Of course only the ones that are supported should be reimplemented. To specify which operations are supported, also reimplement supportedOperations() and return an int there, that is OR'd together using the supported operations from the QNetworkProtocol::Operation enum.
When you implement a network protocol this way, be careful always to emit the correct signals. Also, always emit the finished() signal when an operation is done (on failure or success!). The Qt Network Architecture relies on correctly emitted finished() signals.
For a detailed description of the Qt Network Architecture and also how to implement and use network protocols in Qt, see the Qt Network Documentation.
When the connection state of a network protocol changes it emits the signal connectionStateChanged(). The first argument is one of the following values:
When an operation fails (finishes without success), the QNetworkOperation of the operation returns an error code which is one of the following values:
You should also use these values of error codes when implementing custom network protocols. If this is not possible, you can define your own ones by using an integer value that doesn't conflict with one of these values.
This enum lists all possible operations that a network protocol can support. supportedOperations() returns an int that is OR'd together. Also, the type() or a QNetworkOperation is always one of these values.
This enum contains the state that a QNetworkOperation can have:
See also QNetworkProtocol::setAutoDelete().
If the connection can't be opened (e.g., because you already tried it but the host couldn't be found), set the state of op to QNetworkProtocol::StFailed and emit the finished() signal with this QNetworkOperation as argument.
op is the operation that needs an open connection.
Example: network/networkprotocol/nntp.cpp.
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 and ConClosed. data is a message text.
This signal is emitted when mkdir() has been succesful 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 infos of the operation, including the state, etc. Using op->arg( 0 ), you also get the file name of the new directory.
When a protocol emits this signal, QNetworkProtocol is smart enough to let the QUrlOperator, which is used by the network protocol, emit its corresponding signal.
This signal is emitted when new data has been received after calling get() or put(). op holds the name of the file in which data is retrieved its first argument, and the (raw) data in its second argument. You can fetch them with op->arg( 0 ) and op->rawArg( 1 ).
Note that op contains all information about the operation, including the state.
When a protocol emits this signal, QNetworkProtocol is smart enough to let the QUrlOperator (which is used by the network protocol) emit its corresponding signal.
This signal is emitted during the progress when transferring data (using put() or get()). bytesDone tells how many bytes of bytesTotal are transferred. More information about the operation is stored in the op, the pointer to the network operation which is processed. bytesTotal may be -1, which means that the number of total bytes is not known.
When a protocol emits this signal, QNetworkProtocol is smart enough to let the QUrlOperator, which is used by the network protocol, emit its corresponding signal.
This signal is emitted when an operation of some sort finishes. This signal is always emitted, whether success or failure. op is the pointer to the operation object which contains all infos of the operation that has finished, 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, QNetworkProtocol is smart enough to let the QUrlOperator, which is used by the network protocol, emit its corresponding signal.
QFtp *ftp = QNetworkProtocol::getNetworkProtocol( "ftp" );
This returns null if no protocol for ftp was registered or a pointer to a new instance of an FTP implementation. The ownership of the pointer is transferred to you, so you have to 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 the QUrlOperator, which makes working with network protocols much more convenient.
See also QUrlOperator.
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. You get them with op->arg( 0 ) and op->arg( 1 ).
op is the pointer to the operation object, which contains all infos of the operation, including the state and so on.
When a protocol emits this signal, QNetworkProtocol is smart enough to let the QUrlOperator, which is used by the network protocol, emit its corresponding signal.
This signal is emitted if a new child has been read. QNetworkProtocol automatically connects it to a slot which creates a list of QUrlInfo objects (with just the one QUrlInfo i) and emits the newChildren() signal with this created list.
This is just a convenience signal when implementing your own network protocol. In all other cases worry only about the newChildren() signal with the list of QUrlInfo objects.
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 infos of the operation, including the state, etc.
When a protocol emits this signal, QNetworkProtocol is smart enough to let the QUrlOperator, 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. But if you read only one child at once you can use the convenience signal newChild(), which takes only a single QUrlInfo object.
When you reimplement this method it's very important that you emit the correct signals at the correct time (especially the finished() signal after processing an operation). Take a look at the Qt Network Documentation. It describes in detail how to reimplement this method. You may also look at the example implementation of qt/extenstions/network/examples/networkprotocol/nntp.cpp.
Example: network/networkprotocol/nntp.cpp.
When you reimplement this method it's very important that you emit the correct signals at the correct time (especially the finished() signal after processing an operation). Take a look at the Qt Network Documentation. It describes in detail how to reimplement this method. You may also look at the example implementation of qt/extenstions/network/examples/networkprotocol/nntp.cpp.
Example: network/networkprotocol/nntp.cpp.
When you reimplement this method it's very important that you emit the correct signals at the correct time (especially the finished() signal after processing an operation). Take a look at the Qt Network Documentation. It describes in detail how to reimplement this method. You may also look at the example implementation of qt/extenstions/network/examples/networkprotocol/nntp.cpp.
When you reimplement this method it's very important that you emit the correct signals at the correct time (especially the finished() signal after processing an operation). Take a look at the Qt Network Documentation. It describes in detail how to reimplement this method. You may also look at the example implementation of qt/extenstions/network/examples/networkprotocol/nntp.cpp.
When you reimplement this method it's very important that you emit the correct signals at the correct time (especially the finished() signal after processing an operation). Take a look at the Qt Network Documentation. It is describes in detail how to reimplement this method. You may also look at the example implementation of qt/extenstions/network/examples/networkprotocol/nntp.cpp.
When you reimplement this method it's very important that you emit the correct signals at the correct time (especially the finished() signal after processing an operation). Take a look at the Qt Network Documentation. It describes in detail how to reimplement this method. You may also look at the example implementation of qt/extenstions/network/examples/networkprotocol/nntp.cpp.
QNetworkProtocol::registerNetworkProtocol( "nntp", new QNetworkProtocolFactory This implementation is thereafter registered for nntp operations.
This signal is emitted when remove() has been succesful
and the file has been removed. op holds the file name
of the removed file in the first argument; you get it
with op->arg( 0 ).
op is the pointer to the operation object, which contains all infos
of the operation, including the state and so on.
When a protocol emits this signal, QNetworkProtocol is smart enough
to let the QUrlOperator, which is used by the network protocol, emit
its corresponding signal.
Note that if you switch on auto-delete, the QNetworkProtocol also
deletes its QUrlOperator!
See also QUrlOperator.
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 infos
of the operation, including the state, etc.
When a protocol emits this signal, QNetworkProtocol is smart enough
to let the QUrlOperator, which is used by the network protocol, emit
its corresponding signal.
Example: network/networkprotocol/nntp.cpp.
Search the documentation, FAQ, qt-interest archive and more (uses
www.trolltech.com):
This file is part of the Qt toolkit,
copyright © 1995-2001
Trolltech, all rights reserved.void QNetworkProtocol::removed ( QNetworkOperation * op ) [signal]
void QNetworkProtocol::setAutoDelete ( bool b, int i = 10000 ) [virtual]
Because it's sometimes hard to take care of removing network protocol
instances, QNetworkProtocol provides an auto-delete mechanism. If you
set b to TRUE, the network protocol instance is removed after it has
been i milliseconds inactive (i ms after the last operation has
been processed). If you set b to FALSE the auto-delete mechanism is
switched off.
void QNetworkProtocol::setUrl ( QUrlOperator * u ) [virtual]
Sets the QUrlOperator, on which the protocol works.
void QNetworkProtocol::start ( QNetworkOperation * op ) [signal]
void QNetworkProtocol::stop () [virtual]
Stops the current operation that was just processed and clears
all waiting operations.
int QNetworkProtocol::supportedOperations () const [virtual]
Returns an int that is OR'd together using the enum values
of QNetworkProtocol::Operation, which describes which operations
are supported by the network protocol. Should be reimplemented by new
network protocols.
QUrlOperator * QNetworkProtocol::url () const
Returns the QUrlOperator on which the protocol works.
Copyright © 2001 Trolltech Trademarks