Details
Description
Although the QNetworkReply documentation (here http://qt.nokia.com/doc/4.5/qnetworkreply.html#setReadBufferSize ) says that if you set the read buffer size to something small, "QNetworkReply will try to stop reading from the network once this buffer is full, thus causing the download to throttle down as well," this doesn't seem to be working. If we limit the size of the readbuffer, the API will indeed dole out the download to us in smaller chunks, behind the scenes Qt is actually doing an unthrottled download and caching the data somewhere else. The actual bandwidth usage doesn't seem to be limited at all.
#include <QHBoxLayout> #include <QLabel> #include <QWidget> #include <QApplication> #include <QtNetwork> class MyWidget: public QWidget { Q_OBJECT public: MyWidget(QWidget *parent = 0); private slots: void replyFinished(QNetworkReply*); private: QHBoxLayout *layout; QLabel *label; QNetworkAccessManager *nam; }; MyWidget::MyWidget(QWidget *parent) : QWidget(parent) { setWindowTitle("Support Tester"); layout = new QHBoxLayout; label = new QLabel ("Notice that setReadBufferSize does not change the network usage at all"); layout->addWidget(label); setLayout(layout); nam = new QNetworkAccessManager; QNetworkRequest netRequest(QUrl("http://get.qt.nokia.com/qtcreator/qt-creator-1.2.1-src.zip")); QNetworkReply *m_reply; m_reply = nam->get (netRequest); // m_reply->setReadBufferSize ( 2048 ); //or some other small number connect(nam, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*))); } void MyWidget::replyFinished(QNetworkReply*) { qDebug("finished! now remove comments on setReadBufferSize(2048) "); } //This moc include is to get everything in a single file - for quick testing only #include "main.moc" int main(int argc, char *argv[]) { QApplication app(argc, argv); MyWidget *myWin = new MyWidget(); myWin->show(); return app.exec(); }
Attachments
Issue Links
- is replaced by
-
QTBUG-15065 Fix HTTP QNetworkReply setReadBufferSize() once and for all
- Open
- relates to
-
QTBUG-13431 QNetworkReply: Throttling causes download to fail
- Closed