[Interest] Debugging tip for QNetworkReply

Jason Kretzer Jason at gocodigo.com
Fri May 2 19:45:16 CEST 2014


Good Day!

I am using the following code to download zip files from a url.  The only thing that changes is the “id” in the url(one for each zip).  Anyway, the code always works on one of the zip files, but never works on the other.  Both zips are on the server.  Both zips are downloadable, if I access the url(s) from a web browser.  What I am looking for is primarily direction on how to go about effectively debugging this.  I tried using reply->errorString() right after loop.exec() — but it returns only “Unknown Error” whether the download is successful or not.  It should also be noted that on failure a file is created but is not a readable zip file.

Thanks!

void downloadFile(QUrl url, QString filename)
{
    QNetworkAccessManager* netManager = new QNetworkAccessManager();
    QNetworkRequest request(url);
    QNetworkReply* reply = netManager->get(request);

    QEventLoop loop;
    QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
    loop.exec();

    QFile file(filename);
    file.open(QIODevice::WriteOnly);
    file.write(reply->readAll());
    file.close();
    
    netManager->deleteLater();
    reply->deleteLater();
}



//--------------------------------//
    Jason R. Kretzer
    Lead Application Developer
    jason at gocodigo.com
    606.792.0079
//--------------------------------//





More information about the Interest mailing list