QNetworkProtocol(3qt)

πŸ“¦ version 3.3.8b, in fedora 43, fedora 44

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 () const
  • virtual int supportedOperations () const
  • virtual void addOperation ( QNetworkOperation * op )
  • QUrlOperator * url () const
  • QNetworkOperation * operationInProgress () const
  • virtual 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 is http and no http implementation 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 πŸ’–. op is 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 called protocol. 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] β€” returns TRUE if the only protocol registered is the one for working on the local filesystem, and FALSE if 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 call rename(). op keeps the original and the new file names in the first and second arguments, which you reach with op->arg( 0 ) and op->arg( 1 ) respectively. And op is 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. QNetworkProtocol automatically connects it to a slot that builds a list of QUrlInfo objects (with just one QUrlInfo called i) and emits the newChildren() signal with that list. op is 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 after listChildren() was called and new children (files) have been read from the list of files. i holds the info about the new children, and op is 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 the QNetworkOperation. πŸ“₯

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, or 0 if 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 this QNetworkOperation. πŸ“‚

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 this QNetworkOperation. πŸ“βœ¨

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 the QNetworkOperation. πŸ“€

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 this QNetworkOperation. πŸ—‘οΈ

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 this QNetworkOperation. ✏️

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 (called Nntp) derived from QNetworkProtocol β€” 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 when remove() has been succesful and the file has been removed. op holds the file name of the removed file in the first argument, reachable with op->arg( 0 ). And op is 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 why QNetworkProtocol hands you an auto-delete mechanism 🫢
    • Set b to TRUE and the network protocol instance is removed after it's been inactive for i milliseconds β€” meaning i milliseconds after the last operation was processed.
    • Set b to FALSE and the auto-delete mechanism is switched off.
Heads up bestie: if you switch on auto-delete, the QNetworkProtocol also deletes its QUrlOperator. So like, don't be surprised when that happens πŸ‘€

  • void QNetworkProtocol::setUrl ( QUrlOperator * u ) [virtual] β€” sets the QUrlOperator that the protocol works on to u. 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 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