Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ Qt get HTTP headers from QNetworkRequest
    primarykey
    data
    text
    <p>I am developing a Qt C++ application. I need to download some files (which can be large) and show downloading progress to user. To perform this task, I use this code:</p> <pre><code>QNetworkAccessManager* networkManager = new QNetworkAccessManager(); QNetworkRequest request(fileUrl); //fileUrl is a QUrl variable QVariant responseLength = request.header(QNetworkRequest::ContentLengthHeader); int fileSize = responseLength.toInt(); ui-&gt;progressBar-&gt;setMaximum(fileSize); QNetworkReply reply = networkManager-&gt;get(request); QObject::connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadProgressChanged(qint64,qint64))); </code></pre> <p>Where <code>downloadProgressChanged</code> is a slot with this code:</p> <pre><code>void downloadProgressChanged(qint64 downloaded, qint64 total) { ui-&gt;progressBar-&gt;setValue(ui-&gt;progressBar-&gt;value() + 1); ui-&gt;labelProgress-&gt;setText(QString::number((downloaded / 1024))); } </code></pre> <p>(I use QProgressBar named <code>progressBar</code> to show progress and QLabel named <code>labelProgress</code> to show downloaded kilobytes).</p> <p>My problem is that I can't access Content-Length header (<code>int fileSize</code> value is 0) and so I am not able to show the progress of the operation. I checked HTTP headers on my web-server - Content-Length works fine.</p> <p>In <a href="https://stackoverflow.com/questions/6778118/reading-http-headers">this SO question</a> I read that I can use <code>QNetworkReply::metaDataChanged()</code> signal, but how can I use it to show progress? Documentation says that the signal can be emitted when downloading <strong>has been already started</strong>, but I need to get header content <strong>before</strong> downloading will start - to set up my progressBar.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload