Class: QgsNetworkContentFetcherTask

class qgis.core.QgsNetworkContentFetcherTask(url: QUrl, authcfg: str = '', flags: Union[QgsTask.Flags, QgsTask.Flag] = QgsTask.CanCancel)

Bases: QgsTask

Constructor for a QgsNetworkContentFetcherTask which fetches the specified url.

Optionally, authentication configuration can be set via the authcfg argument.

QgsNetworkContentFetcherTask(request: QNetworkRequest, authcfg: str = ‘’, flags: Union[QgsTask.Flags, QgsTask.Flag] = QgsTask.CanCancel) Constructor for a QgsNetworkContentFetcherTask which fetches the specified network request.

Optionally, authentication configuration can be set via the authcfg argument.

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.

New in version 3.2:

Methods

cancel

childEvent

connectNotify

contentAsString

Returns the fetched content as a string

customEvent

disconnectNotify

finished

If the task is managed by a QgsTaskManager, this will be called after the task has finished (whether through successful completion or via early termination).

isCanceled

Will return True if task should terminate ASAP.

isSignalConnected

receivers

reply

Returns the network reply.

run

rtype

bool

sender

senderSignalIndex

setProgress

Sets the task's current progress.

timerEvent

Signals

fetched

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

cancel(self)
childEvent(self, QChildEvent)
connectNotify(self, QMetaMethod)
contentAsString(self) str

Returns the fetched content as a string

Warning

This should only be accessed from a slot connected directly to the QgsNetworkContentFetcherTask.fetched() signal.

New in version 3.10.

Return type

str

customEvent(self, QEvent)
disconnectNotify(self, QMetaMethod)
fetched

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. [signal]

finished(self, result: bool)

If the task is managed by a QgsTaskManager, this will be called after the task has finished (whether through successful completion or via early termination). The result argument reflects whether the task was successfully completed or not. This method is always called from the main thread, so it is safe to create widgets and perform other operations which require the main thread. However, the GUI will be blocked for the duration of this method so tasks should avoid performing any lengthy operations here.

isCanceled(self) bool

Will return True if task should terminate ASAP. If the task reports the CanCancel flag, then derived classes’ run() methods should periodically check this and terminate in a safe manner.

isSignalConnected(self, QMetaMethod) bool
receivers(self, PYQT_SIGNAL) int
reply(self) QNetworkReply

Returns the network reply. Ownership is not transferred.

May return None if the request has not yet completed.

Warning

This should only be accessed from a slot connected directly to the QgsNetworkContentFetcherTask.fetched() signal.

Return type

QNetworkReply

run(self) bool
Return type

bool

sender(self) QObject
senderSignalIndex(self) int
setProgress(self, progress: float)

Sets the task’s current progress. The derived class should call this method whenever the task wants to update its progress. Calling will automatically emit the progressChanged signal.

Parameters

progress – percent of progress, from 0.0 - 100.0

timerEvent(self, QTimerEvent)