QNetworkProtocol(3qt)
QNetworkProtocol(3qt) π
okay so bestie, welcome to the manual page for QNetworkProtocol(3qt) β the common API for network protocols. no cap, this is the blueprint for making network protocols work in Qt. periodt. π
NAME
QNetworkProtocol - Common API for network protocols β¨
SYNOPSIS
#include <qnetworkprotocol.h>
Inherits QObject.
Inherited by QFtp, QHttp, and QLocalFs.
Public Members
enum State { StWaiting = 0, StInProgress, StDone, StFailed, StStopped }enum Operation { OpListChildren = 1, OpMkDir = 2, OpMkdir = OpMkDir, OpRemove = 4, OpRename = 8, OpGet = 32, OpPut = 64 }enum ConnectionState { ConHostFound, ConConnected, ConClosed }enum Error { NoError = 0, ErrValid, ErrUnknownProtocol, ErrUnsupported, ErrParse, ErrLoginIncorrect, ErrHostNotFound, ErrListChildren, ErrListChlidren = ErrListChildren, ErrMkDir, ErrMkdir = ErrMkDir, ErrRemove, ErrRename, ErrGet, ErrPut, ErrFileNotExisting, ErrPermissionDenied }QNetworkProtocol ()virtual ~QNetworkProtocol ()virtual void setUrl ( QUrlOperator * u )virtual void setAutoDelete ( bool b, int i = 10000 )bool autoDelete () constvirtual int supportedOperations () constvirtual void addOperation ( QNetworkOperation * op )QUrlOperator * url () constQNetworkOperation * operationInProgress () constvirtual void clearOperationQueue ()virtual void stop ()
Signals
void data ( const QByteArray & data, QNetworkOperation * op )void connectionStateChanged ( int state, const QString & data )void finished ( QNetworkOperation * op )void start ( QNetworkOperation * op )void newChildren ( const QValueList<QUrlInfo> & i, QNetworkOperation * op )void newChild ( const QUrlInfo & i, QNetworkOperation * op )void createdDirectory ( const QUrlInfo & i, QNetworkOperation * op )void removed ( QNetworkOperation * op )void itemChanged ( QNetworkOperation * op )void dataTransferProgress ( int bytesDone, int bytesTotal, QNetworkOperation * op )
Static Public Members
void registerNetworkProtocol ( const QString & protocol, QNetworkProtocolFactoryBase * protocolFactory )QNetworkProtocol * getNetworkProtocol ( const QString & protocol )bool hasOnlyLocalFileSystem ()
Protected Members
virtual void operationListChildren ( QNetworkOperation * op )virtual void operationMkDir ( QNetworkOperation * op )virtual void operationRemove ( QNetworkOperation * op )virtual void operationRename ( QNetworkOperation * op )virtual void operationGet ( QNetworkOperation * op )virtual void operationPut ( QNetworkOperation * op )virtual bool checkConnection ( QNetworkOperation * op )
DESCRIPTION
The QNetworkProtocol class provides a common API for network protocols. it's literally the blueprint, bestie. π
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 QUrlOperator.
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 QNetworkProtocol::Operation enum. slay. π₯
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. no cap, this is crucial. π«Ά
For a detailed description of the Qt Network Architecture and how to implement and use network protocols in Qt, see the Qt Network Documentation.
See also Input/Output and Networking.
Member Type Documentation
QNetworkProtocol::ConnectionState
When the connection state of a network protocol changes it emits the signal connectionStateChanged(). The first argument is one of the following values:
QNetworkProtocol::ConHostFound- Host has been found. πQNetworkProtocol::ConConnected- Connection to the host has been established. πQNetworkProtocol::ConClosed- Connection has been closed. πͺ
QNetworkProtocol::Error
When an operation fails (finishes unsuccessfully), the QNetworkOperation of the operation returns an error code which has one of the following values:
QNetworkProtocol::NoError- No error occurred. πQNetworkProtocol::ErrValid- The URL you are operating on is not valid. π«QNetworkProtocol::ErrUnknownProtocol- There is no protocol implementation available for the protocol of the URL you are operating on (e.g. if the protocol ishttpand nohttpimplementation has been registered). πQNetworkProtocol::ErrUnsupported- The operation is not supported by the protocol. π ββοΈQNetworkProtocol::ErrParse- The URL could not be parsed correctly. π΅QNetworkProtocol::ErrLoginIncorrect- You needed to login but the username or password is wrong. πQNetworkProtocol::ErrHostNotFound- The specified host (in the URL) couldn't be found. ποΈQNetworkProtocol::ErrListChildren- An error occurred while listing the children (files). πQNetworkProtocol::ErrMkDir- An error occurred when creating a directory. πQNetworkProtocol::ErrRemove- An error occurred when removing a child (file). ποΈQNetworkProtocol::ErrRename- An error occurred when renaming a child (file). βοΈQNetworkProtocol::ErrGet- An error occurred while getting (retrieving) data. π₯QNetworkProtocol::ErrPut- An error occurred while putting (uploading) data. π€QNetworkProtocol::ErrFileNotExisting- A file which is needed by the operation doesn't exist. π«₯QNetworkProtocol::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.
QNetworkProtocol::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 QNetworkOperation is always one of these values.
QNetworkProtocol::OpListChildren- List the children of a URL, e.g. of a directory. πQNetworkProtocol::OpMkDir- Create a directory. πQNetworkProtocol::OpRemove- Remove a child (e.g. a file). βQNetworkProtocol::OpRename- Rename a child (e.g. a file). π·οΈQNetworkProtocol::OpGet- Get data from a location. π₯QNetworkProtocol::OpPut- Put data to a location. π€
QNetworkProtocol::State
This enum contains the state that a QNetworkOperation can have.
QNetworkProtocol::StWaiting- The operation is in the QNetworkProtocol's queue waiting to be prcessed. πQNetworkProtocol::StInProgress- The operation is being processed. β³QNetworkProtocol::StDone- The operation has been processed succesfully. πQNetworkProtocol::StFailed- The operation has been processed but an error occurred. π₯QNetworkProtocol::StStopped- The operation has been processed but has been stopped before it finished, and is waiting to be processed. π
MEMBER FUNCTION DOCUMENTATION
QNetworkProtocol::QNetworkProtocol ()
Constructor of the network protocol base class. Does some initialization and connecting of signals and slots. π οΈ
QNetworkProtocol::~QNetworkProtocol () [virtual]
Destructor. π
void QNetworkProtocol::addOperation ( QNetworkOperation * op ) [virtual]
Adds the operation op to the operation queue. The operation will be processed as soon as possible. This method returns immediately. πββοΈ
bool QNetworkProtocol::autoDelete () const
Returns TRUE if auto-deleting is enabled; otherwise returns FALSE. β
See also QNetworkProtocol::setAutoDelete().
bool QNetworkProtocol::checkConnection ( QNetworkOperation * 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 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.
void QNetworkProtocol::clearOperationQueue () [virtual]
Clears the operation queue. π§Ή
void QNetworkProtocol::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 QNetworkProtocol::createdDirectory ( const QUrlInfo & i, QNetworkOperation * op ) [signal]
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 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, QNetworkProtocol is smart enough to let the QUrlOperator, which is used by the network protocol, emit its corresponding signal. π§
void QNetworkProtocol::data ( const QByteArray & data, QNetworkOperation * 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, QNetworkProtocol is smart enough to let the QUrlOperator (which is used by the network protocol) emit its corresponding signal. β¨
void QNetworkProtocol::dataTransferProgress ( int bytesDone, int bytesTotal, QNetworkOperation * 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, QNetworkProtocol is smart enough to let the QUrlOperator, which is used by the network protocol, emit its corresponding signal. π«
void QNetworkProtocol::finished ( QNetworkOperation * op )[signal] β bestie, this is THE moment. This signal goes off when an operation finishes, and it is always emitted β success and failure both, no favourites π.opis the pointer to the operation object, and it's holding all the tea: the state, everything. So to figure out if things actually went well, go check the state and error code of that operation object. Don't just assume, okay? π
And here's the cute part: when a protocol emits this signal, QNetworkProtocol is smart enough to let the QUrlOperator (the one the network protocol is using) emit its corresponding signal too. Iconic teamwork β¨
QNetworkProtocol * QNetworkProtocol::getNetworkProtocol ( const QString & protocol )[static] β a static method that hands you a new instance of the network protocol calledprotocol. Say you wanna do some FTP stuff, you'd literally go:
QFtp *ftp = QNetworkProtocol::getNetworkProtocol( "ftp" );
That gives you back a pointer to a fresh instance of an ftp implementation β or null if no protocol for ftp was ever registered, rip π. Heads up tho: ownership is transferred to you, so you must delete it if you don't need it anymore. It's yours now, take care of it π«Ά
Also ngl, you normally shouldn't be working directly with network protocols, so you won't need to call this yourself. Instead use QUrlOperator, which makes working with network protocols so much more convenient β¨
See also QUrlOperator.
bool QNetworkProtocol::hasOnlyLocalFileSystem ()[static] β returnsTRUEif the only protocol registered is the one for working on the local filesystem, andFALSEif other network protocols are also registered. Simple vibe check π¦
void QNetworkProtocol::itemChanged ( QNetworkOperation * op )[signal] β fires whenever a file that's a child of this URL has been changed, like when you successfully callrename().opkeeps the original and the new file names in the first and second arguments, which you reach withop->arg( 0 )andop->arg( 1 )respectively. Andopis the pointer to the operation object holding all the info about the operation, state and all π
When a protocol emits this, QNetworkProtocol is smart enough to let the QUrlOperator (the one the network protocol uses) emit its corresponding signal. Teamwork again, we love to see it π
void QNetworkProtocol::newChild ( const QUrlInfo & i, QNetworkOperation * op )[signal] β this one goes off if a new child (file) has been read.QNetworkProtocolautomatically connects it to a slot that builds a list ofQUrlInfoobjects (with just oneQUrlInfocalledi) and emits thenewChildren()signal with that list.opis the pointer to the operation object containing all the info about the operation that has finished, state etc. πΈ
Real talk: this is just a convenience signal for implementing your own network protocol. In every other case, connect to the newChildren() signal with its list of QUrlInfo objects instead, k? π«Ά
void QNetworkProtocol::newChildren ( const QValueList<QUrlInfo> & i, QNetworkOperation * op )[signal] β this gets emitted afterlistChildren()was called and new children (files) have been read from the list of files.iholds the info about the new children, andopis the pointer to the operation object holding everything about the operation, state etc. π
When a protocol emits this, QNetworkProtocol is smart enough to let the QUrlOperator (the one the network protocol uses) emit its corresponding signal. Yes bestie, same glow-up as always β¨
So when you're implementing your own network protocol and reading children, you usually don't read one child at a time β you read a whole list of them. That's why this signal takes a list of QUrlInfo objects. If you'd rather read just one child at a time, there's the convenience signal newChild(), which takes a single QUrlInfo object. Your call π
void QNetworkProtocol::operationGet ( QNetworkOperation * op )[virtual protected] β when you're building a new network protocol, reimplement this method if the protocol supports getting data; it should then process theQNetworkOperation. π₯
And listen, when you reimplement this it is very important that you emit the correct signals at the correct time (especially the finished() signal after processing an operation). Go look at the Qt Network Documentation, it describes in detail how to reimplement this method. You might also wanna peek at the example implementation in examples/network/networkprotocol/nntp.cpp π§
op is the pointer to the operation object holding all the info on the operation that has finished, state etc.
Example: network/networkprotocol/nntp.cpp.
QNetworkOperation * QNetworkProtocol::operationInProgress () constβ returns the operation that's currently being processed, or0if no operation is being processed at the moment. Nothing happening? You get a big fat zero π
void QNetworkProtocol::operationListChildren ( QNetworkOperation * op )[virtual protected] β when implementing a new network protocol, reimplement this one if the protocol supports listing children (files); it should then process thisQNetworkOperation. π
Same deal as before: when you reimplement this, it's very important that you emit the correct signals at the correct time (especially the finished() signal after processing an operation). Check the Qt Network Documentation for the full breakdown, and there's also the example implementation in examples/network/networkprotocol/nntp.cpp πΈ
op is the pointer to the operation object holding all the info on the operation that has finished, state etc.
Example: network/networkprotocol/nntp.cpp.
void QNetworkProtocol::operationMkDir ( QNetworkOperation * op )[virtual protected] β when implementing a new network protocol, reimplement this if the protocol supports making directories; it should then process thisQNetworkOperation. πβ¨
And yeah, when you reimplement it, it's very important that you emit the correct signals at the correct time (especially the finished() signal after processing an operation). The Qt Network Documentation spells out exactly how to reimplement this method, and there's an example implementation in examples/network/networkprotocol/nntp.cpp π§
op is the pointer to the operation object holding all the info on the operation that has finished, state etc.
void QNetworkProtocol::operationPut ( QNetworkOperation * op )[virtual protected] β when implementing a new network protocol, reimplement this if the protocol supports putting (uploading) data; it should then process theQNetworkOperation. π€
And once again bestie, when you reimplement this it's very important that you emit the correct signals at the correct time (especially the finished() signal after processing an operation). The Qt Network Documentation has the whole detailed how-to, plus there's the example implementation in examples/network/networkprotocol/nntp.cpp π
op is the pointer to the operation object holding all the info on the operation that has finished, state etc.
void QNetworkProtocol::operationRemove ( QNetworkOperation * op )[virtual protected] β when implementing a new network protocol, reimplement this if the protocol supports removing children (files); it should then process thisQNetworkOperation. ποΈ
Yep, same ritual: 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 which is describes in detail how to reimplement this method β (yes, that's exactly how it reads in the original, we're keeping it π
). You may also want to look at the example implementation in examples/network/networkprotocol/nntp.cpp.
op is the pointer to the operation object holding all the info on the operation that has finished, state etc.
void QNetworkProtocol::operationRename ( QNetworkOperation * op )[virtual protected] β when implementing a new newtork protocol (typo in the original, keeping it fr fr π), reimplement this method if the protocol supports renaming children (files); it should then process thisQNetworkOperation. βοΈ
And of course, 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). The Qt Network Documentation describes in detail how to reimplement this method, and there's the example implementation in examples/network/networkprotocol/nntp.cpp π¦
op is the pointer to the operation object holding all the info on the operation that has finished, state etc.
void QNetworkProtocol::registerNetworkProtocol ( const QString & protocol, QNetworkProtocolFactoryBase * protocolFactory )[static] β a static method to register a network protocol for Qt. Say you've got an implementation of NNTP (calledNntp) derived fromQNetworkProtocolβ you'd literally go:
QNetworkProtocol::registerNetworkProtocol( "nntp", new QNetworkProtocolFactory<Nntp> );
and after that your implementation is registered for future nntp operations. Slay π₯
The name of the protocol goes in protocol, and a pointer to the protocol factory goes in protocolFactory.
void QNetworkProtocol::removed ( QNetworkOperation * op )[signal] β this one's emitted whenremove()has been succesful and the file has been removed.opholds the file name of the removed file in the first argument, reachable withop->arg( 0 ). Andopis the pointer to the operation object holding all the info about the operation, state etc. π
When a protocol emits this, QNetworkProtocol is smart enough to let the QUrlOperator (the one the network protocol uses) emit its corresponding signal. Periodt β¨
void QNetworkProtocol::setAutoDelete ( bool b, int i = 10000 )[virtual] β okay so sometimes it's just hard to take care of removing network protocol instances, which is whyQNetworkProtocolhands you an auto-delete mechanism π«Ά- Set
btoTRUEand the network protocol instance is removed after it's been inactive forimilliseconds β meaningimilliseconds after the last operation was processed. - Set
btoFALSEand the auto-delete mechanism is switched off.
- Set
Heads up bestie: if you switch on auto-delete, theQNetworkProtocolalso deletes itsQUrlOperator. So like, don't be surprised when that happens π
void QNetworkProtocol::setUrl ( QUrlOperator * u )[virtual] β sets theQUrlOperatorthat the protocol works on tou. That's it, that's the whole thing π
See also QUrlOperator.
...and that's part 2, bestie. More coming, don't go anywhere π
void QNetworkProtocol::start ( QNetworkOperation * op ) [signal]
Okay so some operations (like listChildren(), for example) throw this signal the literal second they start processing the operation. π
And op? That's the pointer to the operation object, bestie β it's holding all</> the info about the operation, the state, everything. She's the main character of the whole thing tbh.
And here's the cute part: when a protocol emits this signal, QNetworkProtocol is smart enough to let the QUrlOperator β the one being used by the network protocol β emit its own corresponding signal. β¨ Like, it just handles it. No cap.
void QNetworkProtocol::stop () [virtual]
Stops the operation that's currently being processed, and clears out every single waiting operation. π Like closing the group chat AND muting the DMs. Nothing's getting through after this.
int QNetworkProtocol::supportedOperations () const [virtual]
Returns an int that's OR'd together using the enum values of QNetworkProtocol::Operation β and that tells you which operations this network protocol actually supports. π
It's meant to be reimplemented by new network protocols, so if you're out here writing one, this one's on you.
Example: network/networkprotocol/nntp.cpp.
QUrlOperator * QNetworkProtocol::url () const
Returns the QUrlOperator that the protocol is working on. That's it, that's the whole thing. π
π SEE ALSO π
π COPYRIGHT π
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.
π AUTHOR π
Generated automatically from the source code. (No human author to stan, sadly. The machine did it. Iconic behaviour honestly. π€β¨)
π BUGS π
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. π«Ά
The definitive Qt documentation is provided in HTML format; it's located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech. (It's giving "we made this for you but don't @ us" fr fr.)
If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qnetworkprotocol.3qt) and the Qt version (3.3.8).
Not me writing up a whole <red>BUGS</> section and then also asking you to report bugs in the man page itself. The layers. π The self-awareness. We love a transparent queen.
And that's the whole page, bestie!! π¦π You made it to the end, which is lowkey an achievement because this one was LONG. The footer says it came from Trolltech AS, dated 2 February 2007, filed under QNetworkProtocol(3qt) β so if anyone asks where all this came from, that's your receipt. β¨ Slay, go forth, and OR together some operation enums. π
π¦ where this page comes from
- fedora 43: qt3-devel-docs 3.3.8b-102.fc43 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- fedora 44: qt3-devel-docs 3.3.8b-103.fc44 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms