PDA

View Full Version : Problem with downloading a webpage



Fenix Voltres
25th June 2009, 16:46
Hi again,
I want to download source code from a webpage - I've got following code:



QHttp * http;
QFile * file;
file = new QFile("something.txt");

QUrl url("SomeUrl");
http = new QHttp;
http->setHost(url.host(), url.port(80));
http->get(url.path(), file);


Everything compiles well, but my file is sometimes empty or it has not whole webpage code, what should I do?

gsmiko
25th June 2009, 19:20
Hi!

The get function is asynchronous, it sends a request to the server and returns immediately, the QHttp object will emit a requestFinished signal when the request completed. You probably tried to read the results from the file before the request completed.
Note that get function returns a request id, and requestFinished has a request id parameter, this way you'll know which request finished.

Fenix Voltres
25th June 2009, 19:55
Thanks, now I see what this phrase means - I was deleting pointer to a file while httpRequestFinished signal was emitted, but I didn't check it's id - and i t was other signal :p