[Qt-interest] qtconcurrent::run() virtual member methods?
Thiago Macieira
thiago.macieira at trolltech.com
Thu Jun 11 00:14:26 CEST 2009
Liam Staskawicz wrote:
>Hi - I was taking the opportunity of adding timeout functionality to the
>QNetworkAccessManager api to experiment with QtConcurrent a bit. Since
>there doesn't seem to be a built-in way to specify a timeout per
> request, I thought I'd run each request in a thread via QtConcurrent
> and call waitForReadyRead with my appropriate timeout value. Code
> looks roughly like:
First of all, don't use threads. You don't need them. You can do this
without threads.
Second, QNetworkReply does not override waitForReadyRead() from QIODevice.
Here's what that function does:
bool QIODevice::waitForReadyRead(int msecs)
{
Q_UNUSED(msecs);
return false;
}
Third, even if that function worked, you MUST NOT access QObjects in other
threads than the thread they have affinity to. In the special case of
QNetworkReply, you must move ALL replies and the manager into that thread.
That would defeat your purpose.
>something to do with the fact that waitForReadyRead is provided by
>QIODevice? The doc for QtConcurrent::run() is mostly based on a few
>examples so I wasn't able to glean too much more from it.
That's exactly the reason. This function requires a bit more of template
black magic to support passing a function that is not defined at the exact
same class as the object you passed as pointer. It's doable, but starts
getting very ugly very soon.
By the way, you should have also noticed that waitForReadyRead would not
work, since it's defined by QIODevice.
>Secondarily, any other better timeout strategies for
> QNetworkAccessManager would also be welcome!
Yes, QTimer would do just fine. If it fires before finished(), call abort().
--
Thiago Macieira - thiago.macieira (AT) nokia.com
Senior Product Manager - Nokia, Qt Software
Sandakerveien 116, NO-0402 Oslo, Norway
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090611/cf696787/attachment.bin
More information about the Qt-interest-old
mailing list