Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QNetworkReply::setReadBufferSize still ignored



  • Lets see follow small test for QNetworkReply::setReadBufferSize behavour

    readtest.pro: @QT += network
    SOURCES = readtest.cpp
    HEADERS = readtest.h
    @

    readtest.h: @#include <QObject>
    class QNetworkAccessManager;
    class QNetworkReply;
    class ReadTest : public QObject
    {
    Q_OBJECT

    public:
    ReadTest(const char *url);
    

    protected:
    void timerEvent(QTimerEvent *event);
    private:
    QNetworkAccessManager *_access_mgr;
    QNetworkReply *_request;
    };
    @

    readtest.cpp: @#include <QCoreApplication>
    #include <QDebug>
    #include <QNetworkAccessManager>
    #include <QNetworkReply>

    #include "readtest.h"

    ReadTest::ReadTest(const char *url)
    {
    qDebug() << "ReadTest, reading url: " << url;
    _access_mgr = new QNetworkAccessManager(this);
    _request = _access_mgr->get(QNetworkRequest(QUrl(url)));
    _request->setReadBufferSize(1048576);
    startTimer(100);
    }
    void ReadTest::timerEvent(QTimerEvent *)
    {
    qDebug() << "bytesAvailable: " << _request->bytesAvailable();
    _request->readAll();
    }

    int main(int argc, char *argv[])
    {
    QCoreApplication app(argc, argv);
    if (argc > 1)
    {
    new ReadTest(argv[1]);
    app.exec();
    }
    }
    @

    I start this application from command line using some URL as first parameter. I expect QNetworkReply::setReadBufferSize will limit buffer usage and I never see _request->bytesAvailable() more than QNetworkReply::setReadBufferSize value (1048576 in this example).

    It works excactly that way, when the example compiled with Qt4.7.4. When it compled with Qt4.8.0 or 4.8.1 I see some huge number instead which depends only on network bandwidth.

    Is this bug or my misunderstanding?


Log in to reply