Skip to content

Instantly share code, notes, and snippets.

@guruz
Created April 14, 2015 08:48
Show Gist options
  • Save guruz/bf90d9d5f4e61f3bd581 to your computer and use it in GitHub Desktop.
Save guruz/bf90d9d5f4e61f3bd581 to your computer and use it in GitHub Desktop.
#include <QNetworkAccessManager>
#include <QEventLoop>
#include <QUrl>
#include <QDebug>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QObject>
#include <QCoreApplication>
#include <QTimer>
int main(int argc, char**argv) {
QCoreApplication app(argc,argv);
QNetworkAccessManager *manager = new QNetworkAccessManager();
QNetworkReply* reply = manager->get(QNetworkRequest(QUrl("http://ipv4.download.thinkbroadband.com/5MB.zip")));
int buffersize = 1024*1024*1; //1MB
reply->setReadBufferSize(buffersize);
QObject::connect(reply, &QNetworkReply::metaDataChanged, [reply,buffersize](){reply->setReadBufferSize(buffersize); qDebug() << buffersize;});
QEventLoop loop;
QTimer::singleShot(15*1000,[&loop](){ loop.quit();});
loop.exec();
qDebug() << "Bytes available:" << reply->bytesAvailable() << "Buffer Size:" << buffersize;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment