Empty buffer when large Json content is downloaded using QNetworkAccessManager object
Uday More last edited by
I am downloading a json file using an URL and the QNetworkAccessManager class. For smaller files till ~50 MB, I am able to successfully download the files. But when the size increases further, I get a success code as success (200) and when I try to access the Bytearray to from the json content, the bytearray returned is empty.
QString url = "My URL to fetch content";
// Setting the header type requestGetLabels.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
QNetworkAccessManager *restApiClient = new QNetworkAccessManager();
QNetworkReply *replyGetLabels = restApiClient->get(requestGetLabels);
QVariant statusCode = replyGetLabels->attribute(QNetworkRequest::HttpStatusCodeAttribute);
LMSError replyStatus = static_cast<LMSError>(statusCode.toInt());
// Check if the API call is successful.
if(LMSError::SUCCESS == replyStatus) ==> 200 is LMSError::SUCESS
//==> It returns zero bytes here for files
QByteArray bytes = replyGetLabels->readAll();
Also some questions :
- What is the default timeout in seconds for get and a post request ?
@Uday-More you're forcing synchronous behavior on an asynchronous API, thats your problem.
Change it to proper event driven code and also connect to the various error signals of QNetworkAccessManager and QNetworkReply