Important: Please read the Qt Code of Conduct -

Is it possible to control download speed using QNetworkAccessManager

  • Can we restrict QNetworkACCessManager from consuming whole bandwidth, by restricting the download speed, as we do see such options available with almost every download manager

  • What about reducing the "read buffer size": and clearing the buffer at the desired download rate?

  • Thanks for the reply!
    Do you mean that if i set the buffer size to suppose 512kB, it won't cause any data loss.

  • The download should just stall, which means it stops receiving data after 512 kB and waits for the buffer to be emptied. It then continous receiving the next 512 kB of data once done so.

    I haven't verified this, but if you set your read buffer to for example 512 kB an you empty it once a second (using read()), you should theoretically end up with an download rate of (approx.) 512 kB a second.

  • How can we empty the buffer exactly after one second, as it is done through signal/slot mechanism?

  • Use a QTimer and read() once a second.

  • When readyRead() signal is emitted then the following slot is invoked
    @void Download::saveToDisk()

    qint64 bytes;


    How, can i control it using QTimer, it is completely determined by the readyRead() signal. Can you plz explain it more

  • No, it isn't. ;-)
    Just ignore the readyRead() signal and use a QTimer, which periodically empties the read buffer.
    class Downloader : public QObject

    Downloader(QObject *object) : QObject(parent)
    connect(&timer, SIGNAL(timeout()), this, SLOT(processData());

    bool download(const QUrl &url, const QString &fileName, downloadRate = -1)
        if ( | QIODevice::Truncate) == false)
            return false;
        reply = manager.get(QNetworkRequest(url));
        if (downloadRate > 0)
        return true;

    void finished();

    QNetworkAccessManager manager;
    QNetworkReply *reply;
    QTimer timer;

    private slots:
    void processData()

        if (reply->isFinished() == true)
            reply = nullptr;
            emit finished();

    Brain to terminal. Not tested. Exemplary.

  • Thanks a lot for such a detailed answer!

Log in to reply