Hi I want to achieve to download a file in a separate thread and store that file, but I was not able to find an appropriate way to achieve this without evil delay (quite frequent download of small files, so signal+slots are too slow). What I want to achieve: (Pseudo Code)
request file;
wait for download finishing, timeout or error;
save downloaded file;
I'd prefer an example with QNetworkAccessManager if possible. Thanks for any tipp.
Edit: Just to be clear, I want signal and slots not because of design aswell as the lack of speed.
Edit2: This download is only about the download file in sync part, threading is no problem. The problem is that QT does not provide an api for doing that and I am not keen on hotspinning wait.
Edit3: Example code like it should work, but does not:
QNetworkAccessManager net;
QNetworkReply *re (net.get( QNetworkRequest( QUrl( Qstring("www.blah.org/key") ) ) ));
if (re->waitForReadyRead(-1)) //! @bug this does not work as supposed, waitForRead returns false and returns INSTANTLY!!
qDebug() << "ReadyRead yeha!!!";
if (re->error()) {
qDebug() << "Can't download" << re->url().toString()
<< ":" << re->errorString();
} else {
img->load(re->readAll());
qDebug() << "Savin IMG";
}
delete re;