QgsNetworkContentFetcherTask class

Handles HTTP network content fetching in a background task.

Provides a simple method for fetching remote HTTP content in a QgsTask. Url redirects are automatically handled.

After constructing a QgsNetworkContentFetcherTask, callers should connect to the QgsNetworkContentFetcherTask::fetched signal. They can then safely access the network reply() from the connected slot without danger of the task being first removed by the QgsTaskManager.

Base classes

class QgsTask
Abstract base class for long running background tasks.

Constructors, destructors, conversion operators

QgsNetworkContentFetcherTask(const QUrl& url)
Constructor for a QgsNetworkContentFetcherTask which fetches the specified url.
QgsNetworkContentFetcherTask(const QNetworkRequest& request)
Constructor for a QgsNetworkContentFetcherTask which fetches the specified network request.

Public functions

void cancel() override
Notifies the task that it should terminate.
auto reply() -> QNetworkReply*
Returns the network reply.
auto run() -> bool override
Performs the task's operation.

Signals

void fetched()
Emitted when the network content has been fetched, regardless of whether the fetch was successful or not.

Function documentation

void QgsNetworkContentFetcherTask::cancel() override

Notifies the task that it should terminate.

Calling this is not guaranteed to immediately end the task, rather it sets the isCanceled() flag which task subclasses can check and terminate their operations at an appropriate time. Any subtasks owned by this task will also be canceled. Derived classes must ensure that the base class implementation is called from any overridden version.

QNetworkReply* QgsNetworkContentFetcherTask::reply()

Returns the network reply.

Ownership is not transferred.

May return nullptr if the request has not yet completed.

bool QgsNetworkContentFetcherTask::run() override

Performs the task's operation.

This method will be called when the task commences (ie via calling start() ), and subclasses should implement the operation they wish to perform in the background within this method.

A task must return a boolean value to indicate whether the task was completed successfully or terminated before completion.

void QgsNetworkContentFetcherTask::fetched() signal

Emitted when the network content has been fetched, regardless of whether the fetch was successful or not.

Users of QgsNetworkContentFetcherTask should connect to this signal, and from the associated slot they can then safely access the network reply() without danger of the task being first removed by the QgsTaskManager.