PDA

View Full Version : QHttp and QTemporaryFile



maximAL
14th January 2009, 19:12
hi,
i am trying to temporarily download a file for further processing. but for some reason QHttp::get does not like QTemporaryFile, whilst it works with a normal QFile.
The temporary file actually gets created but remains empty.


#include <QtCore>
#include <QtNetwork/QHttp>

#include <cstdio>

int main(int argc, char* argv[])
{
QCoreApplication app(argc, argv);
//QFile file("EDDC.TXT"); // works
QTemporaryFile file; // doesn't work
//file.open(); doesn't help
QHttp http;
http.setHost("weather.noaa.gov");
http.get("/pub/data/observations/metar/decoded/EDDC.TXT", &file);
app.connect(&http, SIGNAL(done(bool)), &app, SLOT(quit()));
app.exec();
getc(stdin); // block so the temporary file won't be deleted yet
}

:eek:

maximAL
16th January 2009, 15:06
problem solved: i had to call flush() on the file before accessing it. no idea though, why it only occured when creating a temporary file.