PDA

View Full Version : Loading in sync



soxs060389
2nd November 2009, 23:36
Hi,
I am writing an application which requires me to download certain images from certain servers.
As this happens very frequently, the usage of signal and slots will make the gui get highcup.

So the question is:

How can I make download in snyc within a thread, without an exec() loop (or even with if there is no other way) like this (which does not work though):


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;

Thx for any reply.

wysota
3rd November 2009, 09:09
Have you seen the article on Keeping the GUI Responsive?

BTW. If your waitForReadyRead() fails, there has to be a reason for it... Probably it's not supported by QNetworkReply.

soxs060389
3rd November 2009, 14:50
This article confirms what I somewhat feared. Thank you.

wysota
3rd November 2009, 17:06
What did you fear exactly?