QHttp::get() is asynchronous. If you do something like this:
QHttp::get returns immediately, before actually download file. http is a heap allocated object, so it survives at and of f(), but file not, and is destroyed. When http obtains file from webserver, tries to write to an invalid location (because file is no longer existant).Qt Code:
void f() { QTemporaryFile temp; temp.open(); http->setHost("localhost"); http->get("/file",&file); }To copy to clipboard, switch view to plain text mode
You should declare both QHttp and QTemporaryFile as pointers and create their instances with new, and catch QHttp signal to know when http request is finished. However QHttp example explains well.
Bookmarks