QUrlOperator(3qt)

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

πŸ’– QUrlOperator πŸ’–

the 3qt manual, bestie β€” yes we're reading Qt docs together, it's a whole vibe πŸ¦‹


✨ NAME ✨

QUrlOperator β€” common operations on URLs πŸ‘‘


🌸 SYNOPSIS 🌸

#include <qurloperator.h>

Inherits QObject and QUrl 🫢

🌈 Public Members 🌈

QUrlOperator ()
QUrlOperator ( const QString & url )
QUrlOperator ( const QUrlOperator & url )
QUrlOperator ( const QUrlOperator & url, const QString & relUrl, bool
    checkSlash = FALSE )
virtual ~QUrlOperator ()
virtual const QNetworkOperation * listChildren ()
virtual const QNetworkOperation * mkdir ( const QString & dirname )
virtual const QNetworkOperation * remove ( const QString & filename )
virtual const QNetworkOperation * rename ( const QString & oldname,
    const QString & newname )
virtual const QNetworkOperation * get ( const QString & location =
    QString::null )
virtual const QNetworkOperation * put ( const QByteArray & data, const
    QString & location = QString::null )
virtual QPtrList<QNetworkOperation> copy ( const QString & from, const
    QString & to, bool move = FALSE, bool toPath = TRUE )
virtual void copy ( const QStringList & files, const QString & dest,
    bool move = FALSE )
virtual bool isDir ( bool * ok = 0 )
virtual void setNameFilter ( const QString & nameFilter )
QString nameFilter () const
virtual QUrlInfo info ( const QString & entry ) const
virtual void stop ()

πŸŽ€ Signals πŸŽ€

void newChildren ( const QValueList<QUrlInfo> & i, QNetworkOperation *
    op )
void finished ( QNetworkOperation * op )
void start ( QNetworkOperation * op )
void createdDirectory ( const QUrlInfo & i, QNetworkOperation * op )
void removed ( QNetworkOperation * op )
void itemChanged ( QNetworkOperation * op )
void data ( const QByteArray & data, QNetworkOperation * op )
void dataTransferProgress ( int bytesDone, int bytesTotal,
    QNetworkOperation * op )
void startedNextCopy ( const QPtrList<QNetworkOperation> & lst )
void connectionStateChanged ( int state, const QString & data )

🧚 Protected Members 🧚

virtual void clearEntries ()
void getNetworkProtocol ()
void deleteNetworkProtocol ()
void qInitNetworkProtocols ()

πŸ’… DESCRIPTION πŸ’…

The QUrlOperator class provides common operations on URLs. periodt. ✨

This class operates on hierarchical structures (such as filesystems) using URLs. Its API facilitates all the common operations: <center>.nf </center> (that's the diagram placeholder from the original, not me being weird, i promise 😭)

You can obtain additional information about the URL with isDir() and info(). If a directory is to be traversed using listChildren(), a name filter can be set with setNameFilter(). name filter?? yes bestie, we're filtering.

A QUrlOperator can be used like this, for example to download a file (and assuming that the FTP protocol is registered):

QUrlOperator *op = new QUrlOperator();
op->copy( QString("ftp://ftp.trolltech.com/qt/source/qt-2.1.0.tar.gz"),
         "file:/tmp" );

If you want to be notified about success/failure, progress, etc., you can connect to QUrlOperator's signals, e.g. to start(), newChildren(), createdDirectory(), removed(), data(), dataTransferProgress(), startedNextCopy(), connectionStateChanged(), finished(), etc. A network operation can be stopped with stop(). πŸ›‘

The class uses the functionality of registered network protocols to perform these operations. Depending of the protocol of the URL, it uses an appropriate network protocol class for the operations. Each of the operation functions of QUrlOperator creates a QNetworkOperation object that describes the operation and puts it into the operation queue for the network protocol used. If no suitable protocol could be found (because no implementation of the necessary network protocol is registered), the URL operator emits errors. not every protocol supports every operation, but error handling deals with this problem. she's resilient, we love that for her πŸ’–

To register the available network protocols, use the qInitNetworkProtocols() function. The protocols currently supported are:

  • FTP,
  • HTTP,
  • local file system.

For more information about the Qt Network Architecture see the Qt Network Documentation.

See also QNetworkProtocol, QNetworkOperation, Input/Output and Networking, and Miscellaneous Classes.


πŸ‘‘ MEMBER FUNCTION DOCUMENTATION πŸ‘‘

QUrlOperator::QUrlOperator ()

Constructs a QUrlOperator with an empty (i.e. invalid) URL. she's empty, she's got potential, main character energy fr fr ✨

QUrlOperator::QUrlOperator ( const QString & url )

Constructs a QUrlOperator using url and parses this string. πŸ”

If you pass strings like "/home/qt" the "file" protocol is assumed. she just KNOWS, okay?? no cap.

QUrlOperator::QUrlOperator ( const QUrlOperator & url )

Constructs a copy of url. 🫢

QUrlOperator::QUrlOperator ( const QUrlOperator & url, const QString & relUrl, bool checkSlash = FALSE )

Constructs a QUrlOperator. The URL on which this QUrlOperator operates is constructed out of the arguments url, relUrl and checkSlash: see the corresponding QUrl constructor for an explanation of these arguments. it's giving delegation, and honestly? iconic.

QUrlOperator::~QUrlOperator () [virtual]

Destructor. πŸ’€ rip boo, she did her thing.

void QUrlOperator::clearEntries () [virtual protected]

Clears the cache of children. 🧹

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

This signal is emitted whenever the URL operator's connection state changes. state describes the new state, which is a QNetworkProtocol::ConnectionState value. πŸ”Œ

data is a string that describes the change of the connection. This can be used to display a message to the user. πŸ’¬

QPtrList<QNetworkOperation> QUrlOperator::copy ( const QString & from, const QString & to, bool move = FALSE, bool toPath = TRUE ) [virtual]

Copies the file from to to. If move is TRUE, the file is moved (copied and removed). from must point to a file and to must point to a directory (into which from is copied) unless toPath is set to FALSE. If toPath is set to FALSE then the to variable is assumed to be the absolute file path (destination file path + file name). The copying is done using the get() and put() operations. If you want to be notified about the progress of the operation, connect to the dataTransferProgress() signal. Bear in mind that the get() and put() operations emit this signal through the QUrlOperator. The number of transferred bytes and the total bytes that you receive as arguments in this signal do not relate to the the whole copy operation; they relate first to the get() and then to the put() operation. Always check what type of operation the signal comes from; this is given in the signal's last argument. ⚠️ read that twice bestie, it's the sneaky part ⚠️

At the end, finished() (with success or failure) is emitted, so check the state of the network operation object to see whether or not the operation was successful. βœ…βŒ

Because a move or copy operation consists of multiple operations (get(), put() and maybe remove()), this function doesn't return a single QNetworkOperation, but rather a list of them. They are in the order: get(), put() and (if applicable) remove(). a whole ensemble cast, not a solo act 🌈

See also get() and put().

void QUrlOperator::copy ( const QStringList & files, const QString & dest, bool move = FALSE ) [virtual]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function. 🫢

Copies the files to the directory dest. If move is TRUE the files are moved, not copied. dest must point to a directory. πŸ“

This function calls copy() for each entry in files in turn. You don't get a result from this function; each time a new copy begins, startedNextCopy() is emitted, with a list of QNetworkOperations that describe the new copy operation. πŸ”

void QUrlOperator::createdDirectory ( const QUrlInfo & i, QNetworkOperation * op ) [signal]

This signal is emitted when mkdir() succeeds and the directory has been created. i holds the information about the new directory. πŸŽ‰

op is a pointer to the operation object, which contains all the information about the operation, including the state. op->arg(0) holds the new directory's name. πŸ“›

See also QNetworkOperation and QNetworkProtocol.

void QUrlOperator::data ( const QByteArray & data, QNetworkOperation * op ) [signal]

This signal is emitted when new data has been received after calling get() or put(). op is a pointer to the operation object which contains all the information about the operation, including the state. op->arg(0) holds the name of the file whose data is retrieved and op->rawArg(1) holds the (raw) data. πŸ“¦

See also QNetworkOperation and QNetworkProtocol.

void QUrlOperator::dataTransferProgress ( int bytesDone, int bytesTotal, QNetworkOperation * op ) [signal]

This signal is emitted during data transfer (using put() or get()). bytesDone specifies how many bytes of bytesTotal have been transferred. More information about the operation is stored in op, a pointer to the network operation that is processed. bytesTotal may be -1, which means that the total number of bytes is not known. πŸ€·β™€οΈ

See also QNetworkOperation and QNetworkProtocol.

void QUrlOperator::deleteNetworkProtocol () [protected]

Deletes the currently used network protocol. πŸ—‘οΈ

void QUrlOperator::finished ( QNetworkOperation * op ) [signal]

This signal is emitted when an operation of some sort finishes, whether with success or failure. op is a pointer to the operation object, which contains all the information, including the state, of the operation which has been finished. Check the state and error code of the operation object to see whether or not the operation was successful. 🏁

See also QNetworkOperation and QNetworkProtocol.


const QNetworkOperation * QUrlOperator::get ( const QString & location = QString::null ) [virtual]

okay BESTIE this is the big one ✨ Tells the network protocol to go get data from location or, if location is QString::null, to grab data from wherever this URL is actually pointing (peep QUrl::fileName() and QUrl::encodedPathAndQuery() for that). What happens after that? depends entirely on the network protocol, no cap.

The data() signal fires when data rolls in. And like β€” because it's genuinely unlikely that all the data shows up in one go, it's super common for data() to fire multiple times. The dataTransferProgress() signal fires while the operation is being processed. At the end, finished() fires (with success or failure, obviously), so check the state of the network operation object to see whether or not the operation actually worked out. πŸ’…

If location is QString::null, the path of this QUrlOperator should point to a file when you use this operation. If location is not empty, it can be a relative URL (a child of the path to which the QUrlOperator points) or an absolute URL.

So fr fr, to get a web page you might do something like this:

QUrlOperator op( "http://www.whatever.org/cgi-bin/search.pl?cmd=Hello" );
op.get();

For most other operations, the path of the QUrlOperator must point to a directory. If you wanna download a file you could do this:

QUrlOperator op( "ftp://ftp.whatever.org/pub" );
// do some other stuff like op.listChildren() or op.mkdir( "new_dir" )
op.get( "a_file.txt" );

This will get the data of ftp://ftp.whatever.org/pub/a_file.txt. πŸŽ€

Never. Ever. Do anything like this:
QUrlOperator op( "http://www.whatever.org/cgi-bin" );
op.get( "search.pl?cmd=Hello" ); // WRONG!

If location is not empty and it's relative, it must not contain any queries or references β€” just the name of a child. So if you need to specify a query or reference, do it the way the first example shows, or just specify the full URL (like http://www.whatever.org/cgi-bin/search.pl?cmd=Hello) as location.

See also copy(). 🫢


void QUrlOperator::getNetworkProtocol () [protected]

Finds a network protocol for the URL and deletes the old network protocol. Out with the old, in with the new, it's giving glow-up energy. πŸ¦‹


QUrlInfo QUrlOperator::info ( const QString & entry ) const [virtual]

Returns the URL information for the child entry, or returns an empty QUrlInfo object if there's no info available about entry. Ngl, info about entry is only available after a successfully finished listChildren() operation. So like, don't come asking before you've done the thing. πŸ™ˆ


bool QUrlOperator::isDir ( bool * ok = 0 ) [virtual]

Returns TRUE if the URL is a directory; otherwise returns FALSE. Heads up though β€” this may not always work correctly if the protocol of the URL is something other than file (local filesystem). If you pass a bool pointer as the ok argument, *ok is set to TRUE if the result of this function is known to be correct, and to FALSE otherwise. So ok is basically the vibe check on the answer. ⭐


void QUrlOperator::itemChanged ( QNetworkOperation * op ) [signal]

This signal is emitted whenever a file which is a child of the URL has been changed β€” for example by successfully calling rename(). op is a pointer to the operation object which contains all the info about the operation, including the state. op->arg(0) holds the original file name and op->arg(1) holds the new file name (if it was changed). iconic little glow-up tracker πŸ’–

See also QNetworkOperation and QNetworkProtocol.


const QNetworkOperation * QUrlOperator::listChildren () [virtual]

Starts listing the children of this URL (e.g. the files in the directory). πŸ‘‘ The start() signal is emitted before the first entry is listed and finished() is emitted after the last one. The newChildren() signal is emitted for each list of new entries. If an error occurs, the finished() signal is emitted, so be sure to check the state of the network operation pointer.

Because the operation may not be executed immediately, a pointer to the QNetworkOperation object created by this function is returned. This object contains all the data about the operation and is used to refer to this operation later (e.g. in the signals that are emitted by the QUrlOperator). The return value can also be 0 if the operation object couldn't be created. 😭

The path of this QUrlOperator must point to a directory (because the children of this directory will be listed), not to a file.


const QNetworkOperation * QUrlOperator::mkdir ( const QString & dirname ) [virtual]

Tries to create a directory (child) with the name dirname. If it's successful, a newChildren() signal with the new child is emitted, and the createdDirectory() signal with the information about the new child is also emitted. The finished() signal (with success or failure) is emitted after the operation has been processed, so check the state of the network operation object to see whether or not the operation was successful. ✨

Because the operation will not be executed immediately, a pointer to the QNetworkOperation object created by this function is returned. This object contains all the data about the operation and is used to refer to this operation later (e.g. in the signals that are emitted by the QUrlOperator). The return value can also be 0 if the operation object couldn't be created.

The path of this QUrlOperator must point to a directory (not a file) because the new directory will be created in this path. πŸŽ€


QString QUrlOperator::nameFilter () const

Returns the name filter of the URL. Simple as that, bestie. πŸ¦‹

See also QUrlOperator::setNameFilter() and QDir::nameFilter().


void QUrlOperator::newChildren ( const QValueList<QUrlInfo> & i, QNetworkOperation * op ) [signal]

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

See also QNetworkOperation and QNetworkProtocol.


const QNetworkOperation * QUrlOperator::put ( const QByteArray & data, const QString & location = QString::null ) [virtual]

This function tells the network protocol to put data in location. If location is empty (QString::null), it puts the data in the location to which the URL points. What happens depends on the network protocol. Depending on the network protocol, some data might come back after putting data, in which case the data() signal is emitted. The dataTransferProgress() signal is emitted during processing of the operation. At the end, finished() (with success or failure) is emitted, so check the state of the network operation object to see whether or not the operation was successful. πŸ’…

If location is QString::null, the path of this QUrlOperator should point to a file when you use this operation. If location is not empty, it can be a relative (a child of the path to which the QUrlOperator points) or an absolute URL.

For putting some data to a file you can do the following:

QUrlOperator op( "ftp://ftp.whatever.com/home/me/filename.dat" );
op.put( data );

For most other operations, the path of the QUrlOperator must point to a directory. If you wanna upload data to a file you could do this:

QUrlOperator op( "ftp://ftp.whatever.com/home/me" );
// do some other stuff like op.listChildren() or op.mkdir( "new_dir" )
op.put( data, "filename.dat" );

This will upload the data to ftp://ftp.whatever.com/home/me/filename.dat. uploaded and slaying πŸ”₯

See also copy().


const QNetworkOperation * QUrlOperator::remove ( const QString & filename ) [virtual]

Tries to remove the file (child) filename. If it succeeds the removed() signal is emitted. finished() (with success or failure) is also emitted after the operation has been processed, so check the state of the network operation object to see whether or not the operation was successful. πŸ’€

Because the operation will not be executed immediately, a pointer to the QNetworkOperation object created by this function is returned. This object contains all the data about the operation and is used to refer to this operation later (e.g. in the signals that are emitted by the QUrlOperator). The return value can also be 0 if the operation object couldn't be created.

The path of this QUrlOperator must point to a directory β€” because if filename is relative, it will try to remove it in this directory.


void QUrlOperator::removed ( QNetworkOperation * op ) [signal]

This signal is emitted when remove() has been succesful and the file has been removed. gone. deleted. not coming back. πŸ’…

op is a pointer to the operation object which contains all the info about the operation, including the state. op->arg(0) holds the name of the file that was removed.

See also QNetworkOperation and QNetworkProtocol.


const QNetworkOperation * QUrlOperator::rename ( const QString & oldname, const QString & newname ) [virtual]

Tries to rename the file (child) called oldname to newname. If it succeeds, the itemChanged() signal is emitted. finished() (with success or failure) is also emitted after the operation has been processed, so check the state of the network operation object to see whether or not the operation was successful. ✨

Because the operation may not be executed immediately, a pointer to the QNetworkOperation object created by this function is returned. This object contains all the data about the operation and is used to refer to this operation later (e.g. in the signals that are emitted by the QUrlOperator). The return value can also be 0 if the operation object couldn't be created.

This path of this QUrlOperator must point to a directory, because oldname and newname are handled relative to this directory. πŸ¦‹


void QUrlOperator::setNameFilter ( const QString & nameFilter ) [virtual]

Sets the name filter of the URL to nameFilter. That's it, that's the function. πŸ’–

See also QDir::setNameFilter().


void QUrlOperator::start ( QNetworkOperation * op ) [signal]

Some operations (such as listChildren()) emit this signal when they start processing the operation. op is a pointer to the operation object which contains all the info about the operation, including the state. and we're off! πŸŽ€

See also QNetworkOperation and QNetworkProtocol.


void QUrlOperator::startedNextCopy ( const QPtrList<QNetworkOperation> & lst ) [signal]

This signal is emitted if copy() starts a new copy operation. lst contains all QNetworkOperations related to this copy operation. next copy, who dis πŸ‘‘

See also copy().


void QUrlOperator::stop () [virtual]

Stops the current network operation and removes all this QUrlOperator's waiting network operations. Everything. Gone. The queue is empty bestie. πŸ›‘


void qInitNetworkProtocols ()

This function registers the network protocols for FTP and HTTP. You must call this function before you use QUrlOperator for these protocols. No skipping steps, okay? πŸ™ˆ

This function is declared in qnetwork.h.


🌈 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 πŸ’–

okay so who's the genius behind this page? bestie, literally nobody πŸ’€ it was Generated automatically from the source code. No human author, no signature, just the machine doing its thing and honestly? iconic. πŸ‘‘


😭 BUGS 😭

Found a bug in Qt? Not the vibe, bestie. Report it exactly how they describe at http://doc.trolltech.com/bughowto.html β€” good bug reports help them help you. Thank you πŸ’– (yes they really said thank you, and they meant it, so be nice and give them a good one).

Real talk though: the definitive Qt documentation is provided in HTML format, and it lives at $QTDIR/doc/html β€” you can read it with Qt Assistant or with a plain old web browser. This man page is provided as a convenience for those users who prefer man pages, even though this format is not officially supported by Trolltech. So like... it's a little treat, not the main course πŸ“

And if you find errors in this manual page itself, report them to qt-bugs@trolltech.com. Please include the name of the manual page (qurloperator.3qt) and the Qt version (3.3.8) β€” those two lil details are the whole assignment, don't skip them πŸ™ˆ

fr fr, a bug report without the version number is giving "left on read" energy. include both, always. πŸ’…

and that's the whole page, bestie!! 🌈 this one came straight from Trolltech AS, dated 2 February 2007, and the page itself is QUrlOperator(3qt) ✨ go forth and operate on urls responsibly, mwah πŸ’œπŸ¦‹

πŸ“¦ where this page comes from