Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |
The QUrlOperator class provides common operations on URLs. More...
#include <qurloperator.h>
The QUrlOperator class provides common operations on URLs.
This class operates on hierarchical structures (such as filesystems) using URLs. Its API allows all the common operations (listing children, removing children, renaming, etc.). 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.
A QUrlOperator can be used like this e.g. for downloading a file:
QUrlOperator op; op.copy( QString("ftp://ftp.trolltech.com/qt/source/qt-2.1.0.tar.gz"), "file:/tmp" );
You will also need to connect to some signals of the QUrlOperator to be informed of success, errors, progress and more things.
Of course an implementation for the FTP protocol has to be registered for this example to work, e.g. QFtp. You can use the function qInitNetworkProtocols() to register all the network protocols that are shipped with the Qt network extension (at the moment FTP, HTTP and local file system are supported).
For more information about the Qt Network Architecture see the Qt Network Documentation.
See also QNetworkProtocol, QNetworkOperation, Input/Output and Networking and Miscellaneous Classes.
If you pass strings like "/home/qt" the "file" protocol is assumed.
This signal is emitted whenever the state of the connection of the network protocol of the URL operator 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.
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().
Copies 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 one after the other. 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.
This signal is emitted when mkdir() succeeds 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. Using op->arg(0) you also get the file name of the new directory.
See also QNetworkOperation and QNetworkProtocol.
This signal is emitted when new data has been received after calling get() or put(). op holds the name of the file whose data is retrieved in op->arg( 0 ) and the (raw) data in op->rawArg( 1 ).
op is the pointer to the operation object which contains all the information about the operation, including the state.
See also QNetworkOperation and QNetworkProtocol.
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, the 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.
This signal is emitted when an operation of some sort finishes, whether with success or failure. op is the 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.
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.
For example, 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 want to download a file you could do the following:
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 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 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 as shown in the first example or specify the full URL (such as http://www.whatever.org/cgi-bin/search.pl?cmd=Hello) as location.
See also copy().
This signal is emitted whenever a file which is a child of the URL has been changed, for example by successfully calling rename(). op holds the original and new file names in the first and second arguments, respectively; they can be accessed with op->arg( 0 ) and op->arg( 1 ).
op is the pointer to the operation object which contains all the information about the operation, including the state.
See also QNetworkOperation and QNetworkProtocol.
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 to point to a directory (because the children of this directory will be listed), not to a file.
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 to point to a directory because the new directory will be created in this path, not to a file.
See also QUrlOperator::setNameFilter() and QDir::nameFilter().
This signal is emitted after listChildren() was called and new children (e.g. files) have been read from a 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.
See also QNetworkOperation and QNetworkProtocol.
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" ); op.put( data );
For most other operations, however, the path of the QUrlOperator must point to a directory. If you want to upload data to a file you could do the following:
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.
See also copy().
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.
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 which can be accessed with op->arg( 0 ).
op is the pointer to the operation object which contains all the information about the operation, including the state.
See also QNetworkOperation and QNetworkProtocol.
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 to point to a directory because oldname and newname are handled relative to this directory.
See also QDir::setNameFilter().
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.
See also QNetworkOperation and QNetworkProtocol.
This signal is emitted if copy() starts a new copy operation. lst contains all QNetworkOperations related to this copy operation.
See also copy().
This function registers the network protocols for FTP and HTTP. You have to call this function before you use QUrlOperator for these protocols.
This function is declared in qnetwork.h.
This file is part of the Qt toolkit. Copyright © 1995-2002 Trolltech. All Rights Reserved.
Copyright © 2002 Trolltech | Trademarks | Qt version 3.0.4
|