QGIS API Documentation
3.6.0-Noosa (5873452)
|
A thread safe class for performing blocking (sync) network requests, with full support for QGIS proxy and authentication settings. More...
#include <qgsblockingnetworkrequest.h>
Public Types | |
enum | ErrorCode { NoError, NetworkError, TimeoutError, ServerExceptionError } |
Error codes. More... | |
Public Slots | |
void | abort () |
Aborts the network request immediately. More... | |
Signals | |
void | downloadFinished () |
Emitted once a request has finished downloading. More... | |
void | downloadProgress (qint64, qint64) |
Emitted when when data arrives during a request. More... | |
Public Member Functions | |
QgsBlockingNetworkRequest () | |
Constructor for QgsBlockingNetworkRequest. More... | |
~QgsBlockingNetworkRequest () override | |
QString | authCfg () const |
Returns the authentication config id which will be used during the request. More... | |
QString | errorMessage () const |
Returns the error message string, after a get() or post() request has been made. More... | |
ErrorCode | get (QNetworkRequest &request, bool forceRefresh=false, QgsFeedback *feedback=nullptr) |
Performs a "get" operation on the specified request. More... | |
ErrorCode | post (QNetworkRequest &request, const QByteArray &data, bool forceRefresh=false, QgsFeedback *feedback=nullptr) |
Performs a "post" operation on the specified request, using the given data. More... | |
QgsNetworkReplyContent | reply () const |
Returns the content of the network reply, after a get() or post() request has been made. More... | |
void | setAuthCfg (const QString &authCfg) |
Sets the authentication config id which should be used during the request. More... | |
A thread safe class for performing blocking (sync) network requests, with full support for QGIS proxy and authentication settings.
This class should be used whenever a blocking network request is required. Unlike implementations which rely on QApplication::processEvents() or creation of a QEventLoop, this class is completely thread safe and can be used on either the main thread or background threads without issue.
Redirects are automatically handled by the class.
After completion of a request, the reply content should be retrieved by calling getReplyContent(). This method returns a QgsNetworkReplyContent container, which is safe and cheap to copy and pass between threads without issue.
Definition at line 46 of file qgsblockingnetworkrequest.h.
Error codes.
Definition at line 52 of file qgsblockingnetworkrequest.h.
|
explicit |
Constructor for QgsBlockingNetworkRequest.
Definition at line 31 of file qgsblockingnetworkrequest.cpp.
|
override |
Definition at line 36 of file qgsblockingnetworkrequest.cpp.
|
slot |
Aborts the network request immediately.
Definition at line 224 of file qgsblockingnetworkrequest.cpp.
QString QgsBlockingNetworkRequest::authCfg | ( | ) | const |
Returns the authentication config id which will be used during the request.
Definition at line 47 of file qgsblockingnetworkrequest.cpp.
|
signal |
Emitted once a request has finished downloading.
|
signal |
Emitted when when data arrives during a request.
|
inline |
Returns the error message string, after a get() or post() request has been made.
\
Definition at line 112 of file qgsblockingnetworkrequest.h.
QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::get | ( | QNetworkRequest & | request, |
bool | forceRefresh = false , |
||
QgsFeedback * | feedback = nullptr |
||
) |
Performs a "get" operation on the specified request.
If forceRefresh is false then previously cached replies may be used for the request. If it is set to true then a new query is always performed.
If an authCfg() has been set, then any authentication configuration required will automatically be applied to request. There is no need to manually apply the authentication to the request prior to calling this method.
The optional feedback argument can be used to abort ongoing requests.
The method will return NoError if the get operation was successful. The contents of the reply can be retrieved by calling reply().
If an error was encountered then a specific ErrorCode will be returned, and a detailed error message can be retrieved by calling errorMessage().
Definition at line 57 of file qgsblockingnetworkrequest.cpp.
QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::post | ( | QNetworkRequest & | request, |
const QByteArray & | data, | ||
bool | forceRefresh = false , |
||
QgsFeedback * | feedback = nullptr |
||
) |
Performs a "post" operation on the specified request, using the given data.
If forceRefresh is false then previously cached replies may be used for the request. If it is set to true then a new query is always performed.
If an authCfg() has been set, then any authentication configuration required will automatically be applied to request. There is no need to manually apply the authentication to the request prior to calling this method.
The optional feedback argument can be used to abort ongoing requests.
The method will return NoError if the get operation was successful. The contents of the reply can be retrieved by calling reply().
If an error was encountered then a specific ErrorCode will be returned, and a detailed error message can be retrieved by calling errorMessage().
Definition at line 62 of file qgsblockingnetworkrequest.cpp.
|
inline |
Returns the content of the network reply, after a get() or post() request has been made.
Definition at line 117 of file qgsblockingnetworkrequest.h.
void QgsBlockingNetworkRequest::setAuthCfg | ( | const QString & | authCfg | ) |
Sets the authentication config id which should be used during the request.
Definition at line 52 of file qgsblockingnetworkrequest.cpp.