Class: QgsNetworkContentFetcherTask

class qgis.core.QgsNetworkContentFetcherTask

Bases: QgsTask

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.

QgsNetworkContentFetcherTask(url: QUrl, authcfg: str = ‘’, flags: Union[QgsTask.Flags, QgsTask.Flag] = QgsTask.CanCancel) 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.

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

errorOccurred

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

fetched

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

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)
errorOccurred

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type

PYQT_SIGNAL

fetched

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type

PYQT_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)