QUrlOperator Class Reference
|
Operation | Function |
---|---|
List files | listChildren() |
Make a directory | mkdir() |
Remove a file | remove() |
Rename a file | rename() |
Get a file | get() |
Put a file | put() |
Copy a file | copy() |
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().
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.
To register the available network protocols, use the qInitNetworkProtocols() function. The protocols currently supported are:
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 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.
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 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.
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.
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.
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.
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.
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 is a pointer to the operation object which contains all the information 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).
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 (not a file) because the new directory will be created in this path.
See also QUrlOperator::setNameFilter() and QDir::nameFilter().
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 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.dat" ); op.put( data );
For most other operations, 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 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 that was removed.
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 a 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 must 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-2003 Trolltech. All Rights Reserved.
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 3.2 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com