QGIS API Documentation  3.24.2-Tisler (13c1a02865)
Public Types | Public Slots | Signals | Public Member Functions | List of all members
QgsBlockingNetworkRequest Class Reference

A thread safe class for performing blocking (sync) network requests, with full support for QGIS proxy and authentication settings. More...

#include <qgsblockingnetworkrequest.h>

Inheritance diagram for QgsBlockingNetworkRequest:
Inheritance graph
[legend]

Public Types

enum  ErrorCode { NoError , NetworkError , TimeoutError , ServerExceptionError }
 Error codes. More...
 

Public Slots

void abort ()
 Aborts the network request immediately. More...
 

Signals

Q_DECL_DEPRECATED void downloadFinished ()
 Emitted once a request has finished downloading. More...
 
void downloadProgress (qint64, qint64)
 Emitted when when data arrives during a request. More...
 
void finished ()
 Emitted once a request has finished. More...
 
void uploadProgress (qint64, qint64)
 Emitted when when data are sent 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...
 
ErrorCode deleteResource (QNetworkRequest &request, QgsFeedback *feedback=nullptr)
 Performs a "delete" operation on the specified 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 head (QNetworkRequest &request, bool forceRefresh=false, QgsFeedback *feedback=nullptr)
 Performs a "head" operation on the specified request. More...
 
ErrorCode post (QNetworkRequest &request, const QByteArray &data, bool forceRefresh=false, QgsFeedback *feedback=nullptr)
 This is an overloaded function. More...
 
ErrorCode post (QNetworkRequest &request, QIODevice *data, bool forceRefresh=false, QgsFeedback *feedback=nullptr)
 Performs a "post" operation on the specified request, using the given data. More...
 
ErrorCode put (QNetworkRequest &request, const QByteArray &data, QgsFeedback *feedback=nullptr)
 This is an overloaded function. More...
 
ErrorCode put (QNetworkRequest &request, QIODevice *data, QgsFeedback *feedback=nullptr)
 Performs a "put" 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...
 

Detailed Description

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.

Since
QGIS 3.6

Definition at line 46 of file qgsblockingnetworkrequest.h.

Member Enumeration Documentation

◆ ErrorCode

Error codes.

Enumerator
NoError 

No error was encountered.

NetworkError 

A network error occurred.

TimeoutError 

Timeout was reached before a reply was received.

ServerExceptionError 

An exception was raised by the server.

Definition at line 52 of file qgsblockingnetworkrequest.h.

Constructor & Destructor Documentation

◆ QgsBlockingNetworkRequest()

QgsBlockingNetworkRequest::QgsBlockingNetworkRequest ( )
explicit

Constructor for QgsBlockingNetworkRequest.

Definition at line 32 of file qgsblockingnetworkrequest.cpp.

◆ ~QgsBlockingNetworkRequest()

QgsBlockingNetworkRequest::~QgsBlockingNetworkRequest ( )
override

Definition at line 37 of file qgsblockingnetworkrequest.cpp.

Member Function Documentation

◆ abort

void QgsBlockingNetworkRequest::abort ( )
slot

Aborts the network request immediately.

Definition at line 279 of file qgsblockingnetworkrequest.cpp.

◆ authCfg()

QString QgsBlockingNetworkRequest::authCfg ( ) const

Returns the authentication config id which will be used during the request.

See also
setAuthCfg()

Definition at line 48 of file qgsblockingnetworkrequest.cpp.

◆ deleteResource()

QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::deleteResource ( QNetworkRequest &  request,
QgsFeedback feedback = nullptr 
)

Performs a "delete" operation on the specified request.

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().

Since
3.18

Definition at line 96 of file qgsblockingnetworkrequest.cpp.

◆ downloadFinished

Q_DECL_DEPRECATED void QgsBlockingNetworkRequest::downloadFinished ( )
signal

Emitted once a request has finished downloading.

Deprecated:
Use the finished() signal instead.

◆ downloadProgress

void QgsBlockingNetworkRequest::downloadProgress ( qint64  ,
qint64   
)
signal

Emitted when when data arrives during a request.

◆ errorMessage()

QString QgsBlockingNetworkRequest::errorMessage ( ) const
inline

Returns the error message string, after a get() or post() request has been made.

\

Definition at line 188 of file qgsblockingnetworkrequest.h.

◆ finished

void QgsBlockingNetworkRequest::finished ( )
signal

Emitted once a request has finished.

◆ get()

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().

See also
post()

Definition at line 58 of file qgsblockingnetworkrequest.cpp.

◆ head()

QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::head ( QNetworkRequest &  request,
bool  forceRefresh = false,
QgsFeedback feedback = nullptr 
)

Performs a "head" 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().

Since
3.18

Definition at line 77 of file qgsblockingnetworkrequest.cpp.

◆ post() [1/2]

QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::post ( QNetworkRequest &  request,
const QByteArray &  data,
bool  forceRefresh = false,
QgsFeedback feedback = nullptr 
)

This is an overloaded function.

Performs a "post" operation on the specified request, using the given data.

Definition at line 63 of file qgsblockingnetworkrequest.cpp.

◆ post() [2/2]

QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::post ( QNetworkRequest &  request,
QIODevice *  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().

See also
get()
Since
3.22

Definition at line 71 of file qgsblockingnetworkrequest.cpp.

◆ put() [1/2]

QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::put ( QNetworkRequest &  request,
const QByteArray &  data,
QgsFeedback feedback = nullptr 
)

This is an overloaded function.

Performs a "put" operation on the specified request, using the given data.

Since
3.18

Definition at line 82 of file qgsblockingnetworkrequest.cpp.

◆ put() [2/2]

QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::put ( QNetworkRequest &  request,
QIODevice *  data,
QgsFeedback feedback = nullptr 
)

Performs a "put" operation on the specified request, using the given data.

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().

Since
3.22

Definition at line 90 of file qgsblockingnetworkrequest.cpp.

◆ reply()

QgsNetworkReplyContent QgsBlockingNetworkRequest::reply ( ) const
inline

Returns the content of the network reply, after a get() or post() request has been made.

Definition at line 193 of file qgsblockingnetworkrequest.h.

◆ setAuthCfg()

void QgsBlockingNetworkRequest::setAuthCfg ( const QString &  authCfg)

Sets the authentication config id which should be used during the request.

See also
authCfg()

Definition at line 53 of file qgsblockingnetworkrequest.cpp.

◆ uploadProgress

void QgsBlockingNetworkRequest::uploadProgress ( qint64  ,
qint64   
)
signal

Emitted when when data are sent during a request.

Since
QGIS 3.22

The documentation for this class was generated from the following files: