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. |
|
- 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
authcfgargument.Since QGIS 3.28 the optional
descriptioncan 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
authcfgargument.Since QGIS 3.28 the optional
descriptioncan 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[source]¶
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.
- signal fetched[source]¶
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.
- reply(self) QNetworkReply | None[source]¶
Returns the network reply. Ownership is not transferred.
May return
Noneif 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]