Question

i'm trying to implement a simple downloader. but i'm stucked because my reply and its header is empty.

#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"
#include <QNetworkRequest>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QtDebug>

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QtQuick2ApplicationViewer viewer;
    viewer.setMainQmlFile(QStringLiteral("qml/reply/main.qml"));
    viewer.showExpanded();

    QUrl url("http://www.speedtest.qsc.de/10MB.qsc");
    QNetworkRequest request( url );
    request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
    QByteArray range;
    range = "bytes=" + QByteArray::number( 0 ) + "-";
    request.setRawHeader("Range", range );
    QNetworkAccessManager accessManager;
    QNetworkReply* reply = accessManager.get( request );
    qDebug() << __FILE__ << ":" << __LINE__ << reply->size();
    QList<QByteArray> headerFields = reply->rawHeaderList();
    qDebug() << __FILE__ << ":" << __LINE__ << headerFields.count();
    for( qint64 i = 0; 0 < headerFields.count(); i++ ) {
        QString string( headerFields.at(i));
        qDebug() << __FILE__ << ":" << __LINE__ << string;
    }

    return app.exec();
}

what do i have to do, so that my reply isn't empty anymore? thanks in advance!

Was it helpful?

Solution

I used multiple QNetworkAccessManager, so that's what caused problems because I didn't know that I should only use one per app.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top