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 specifiedurl
.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 networkrequest
.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 theQgsNetworkContentFetcherTask
.fetched signal. They can then safely access the networkreply()
from the connected slot without danger of the task being first removed by theQgsTaskManager
.See also
Methods
Returns the fetched content as a string
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).Will return
True
if task should terminate ASAP.Returns the network reply.
- rtype
bool
Sets the task’s current progress.
Signals
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 networkreply()
without danger of the task being first removed by theQgsTaskManager
. [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)¶