Using QNetworkAccessManager to download a big file.
-
I need to download and write a big file. In order to to this I'm Using QNetworkAccessManager. The problem is that I need to write the file directly but the write procedure is very slow because the special drive is not fast as an hard disk.
QNetworkAccessManager NetworkAccessManager; QNetworkReply *pQNetworkReply= NetworkAccessManager.get(QNetworkRequest(QUrl::fromEncoded(Path.toLocal8Bit()))); QByteArray QBABuffer; if (pQNetworkReply) { connect(pQNetworkReply, &QNetworkReply::readyRead, [&]() { ...
The problem is that the readyread implementation must be fast. If I write in it a slow function the software firtly increase the ram usage and then goes to crash.
Is there a way to pause the object QNetworkReply or to reduce the speed of the dowloader? -
Hi,
If I remember correctly one thing you could do is to set a small read buffer size so it should slow the transmission.
-
After a long brainstorming till the brain explosion I have decided to use the QTcpSocket object implementing the http request by hand like this
QTcpSocket TcpSocket; TcpSocket.connectToHost(Url.host(), Url.port()); if (TcpSocket.waitForConnected()) { TcpSocket.write(QString("GET "+ Url.path()+ " HTTP/1.1\r\n").toLatin1()); TcpSocket.write(QString("Host "+ Url.host()+ " \r\n").toLatin1()); TcpSocket.write(QString("Connection: close\r\n\r\n").toLatin1()); if (TcpSocket.waitForBytesWritten()) { while (TcpSocket.waitForReadyRead()) { ...
Seems to work