Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-6276

QNetworkReply Throttling issue

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 4.6.2, 4.7.2
    • 4.5.3
    • Network
    • None
    • Windows and Mac
    • 36dcdcdf5b6869ded0401a879b1397ad9d20b324, 6bf640a7600132c02742a2581402e04f75b60962, a1ae7da4cfc007b4ae32504af5b2ca9469b21401

    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

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              mgoetz Markus Goetz (Inactive)
              dettman Dean Dettman (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes