bandwidth throttling with Qt

允我心安 提交于 2019-12-06 04:39:45

I ended up using the RcTcpSocket and RateController from this article with the QHttp class. Prior to making get/post requests with the QHttp I create a RcTcpSocket, add it to my RateController and use QHttp::setSocket(QTcpSocket*). I still didn't find a solution to keep using QNetworkAccessManager but this is close enough and works very good.

You should have a look at QNetworkReply::setReadBufferSize(qint64 size). I quote the doc:

QNetworkReply will try to stop reading from the network once this buffer is full (i.e., bytesAvailable() returns size or more), thus causing the download to throttle down as well. If the buffer is not limited in size, QNetworkReply will try to download as fast as possible from the network.

I guess you could play on this value, and maybe the value you get from the downloadProgress() signal to slow things down. I think it should be pretty hard to get something precise with it, but it's probably doable.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!