• QWebDownload
  • QBatchWebDownload
  • QBatchWebDownload Class

    Downloads multiple URLs in parallel by wrapping QWebDownload. More...

    Header: #include <QBatchWebDownload>

    Public Functions

    QBatchWebDownload(int timeoutMs = 30000, int maxRedirects = 10, QObject *parent = nullptr, QNetworkAccessManager *networkManager = nullptr)
    void abort()
    void get(const QList<QUrl> &urls)
    QMap<QUrl, BatchWebDownloadResult> results() const

    Signals

    void finished()
    void progress(int completed, int total)

    Detailed Description

    Use case: You need to download multiple things and wait for all the results before proceeding.

    Basic usage

    QBatchWebDownload batch;
    connect(&batch, &QBatchWebDownload::finished, this, [&batch]() {
        for (auto it = batch.results().constBegin(); it != batch.results().constEnd(); ++it) {
            if (it.value().success) {
                qDebug() << it.key() << "->" << it.value().data.size() << "bytes";
            }
        }
    });
    batch.get({QUrl("https://example.com/a"), QUrl("https://example.com/b")});

    See also QWebDownload and BatchWebDownloadResult.

    Member Function Documentation

    [explicit] QBatchWebDownload::QBatchWebDownload(int timeoutMs = 30000, int maxRedirects = 10, QObject *parent = nullptr, QNetworkAccessManager *networkManager = nullptr)

    \paramtimeoutMs \param maxRedirects \param parent \param networkManager If specified, caller is responsible for its lifecycle.

    void QBatchWebDownload::abort()

    Abort all pending downloads.

    [signal] void QBatchWebDownload::finished()

    Emitted when all downloads complete (success or failure).

    void QBatchWebDownload::get(const QList<QUrl> &urls)

    Start downloading a list of URLs, emits finished() when done.

    [signal] void QBatchWebDownload::progress(int completed, int total)

    Emitted as downloads complete to show progress.

    \paramcompleted Number of completed downloads \param total Total number of downloads

    QMap<QUrl, BatchWebDownloadResult> QBatchWebDownload::results() const

    Get the results (after finished() is emitted.)