Class: QgsNetworkContentFetcherTask¶
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
.
See also
Added in version 3.2.
Class Hierarchy¶
Base classes¶
Abstract base class for long running background tasks. |
|
Methods
Returns the fetched content as a string |
|
Returns the associated filename from the reply's content disposition header, if present. |
|
Returns the network reply. |
Signals
Emitted when an error with code error occurred while processing the request errorMsg is a textual description of the error |
|
Emitted when the network content has been fetched, regardless of whether the fetch was successful or not. |
- class qgis.core.QgsNetworkContentFetcherTask[source]¶
Bases:
QgsTask
- __init__(url: QUrl, authcfg: str | None = '', flags: QgsTask.Flags | QgsTask.Flag = QgsTask.CanCancel, description: str | None = '')
Constructor for a QgsNetworkContentFetcherTask which fetches the specified
url
.Optionally, authentication configuration can be set via the
authcfg
argument.Since QGIS 3.28 the optional
description
can be explicitly set. If not specified, a default task description will be generated.- Parameters:
url (QUrl)
authcfg (Optional[str] = '')
flags (Union[QgsTask.Flags, QgsTask.Flag] = QgsTask.CanCancel)
description (Optional[str] = '')
- __init__(request: QNetworkRequest, authcfg: str | None = '', flags: QgsTask.Flags | QgsTask.Flag = QgsTask.CanCancel, description: str | None = '')
Constructor for a QgsNetworkContentFetcherTask which fetches the specified network
request
.Optionally, authentication configuration can be set via the
authcfg
argument.Since QGIS 3.28 the optional
description
can be explicitly set. If not specified, a default task description will be generated.- Parameters:
request (QNetworkRequest)
authcfg (Optional[str] = '')
flags (Union[QgsTask.Flags, QgsTask.Flag] = QgsTask.CanCancel)
description (Optional[str] = '')
- contentAsString(self) str [source]¶
Returns the fetched content as a string
Warning
This should only be accessed from a slot connected directly to the
QgsNetworkContentFetcherTask.fetched()
signal.Added in version 3.10.
- Return type:
str
- contentDispositionFilename(self) str [source]¶
Returns the associated filename from the reply’s content disposition header, if present.
Added in version 3.28.
- Return type:
str
- signal errorOccurred(code: QNetworkReply.NetworkError, errorMsg: str)[source]¶
Emitted when an error with
code
error occurred while processing the requesterrorMsg
is a textual description of the errorAdded in version 3.22.
- Parameters:
code (QNetworkReply.NetworkError)
errorMsg (str)
- signal fetched[source]¶
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
.
- reply(self) QNetworkReply | None [source]¶
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:
Optional[QNetworkReply]