[SOLVED]Download file without main event loop
-
Hi!
I'd like to download a file, so that when download is started, it does not does not execute next command until file is downloaded.
An example of what I want:
QNetworkAccessManager nam; QNetworkReply *r = nam.get(QNetworkRequest(QUrl("http://URL"))); QByteArray data = r.readAll(); // Everything already downloaded, even if file is several GB in size
I want my app to download a file, save it, and then exit. Nothing more. It'll be started with QProcess, so there will be no GUI and no Qt event loop.
Regards,
Jake -
It's actually a bad idea. get() is already asynchronous so you don't need to put it in an explicit QProcess.
But if you have to, the very ugly solution would be something like this:QNetworkAccessManager nam; QNetworkReply *r = nam.get(QNetworkRequest(QUrl("http://URL"))); while(!r->isFinished()) qApp->processEvents(); QByteArray data = r.readAll(); // Everything already downloaded, even if files is several GB in size
-
My plan was, that I'd retrieve current version of the program from the updater, because it already has all functions written for version checking, updating...
I'd start it with parameter, -v for example, and in this case program would only retrieve and output latest version. Main program would correctly correspond to received message.But based on your solution ( ugly as you said), I'll probably just copy the code, or create a shared library ( just thought of this solution).
Thanks!
Regards,
Jake