[Qt-interest] QNetworkAccessManager & 2 threads

Thiago Macieira thiago at kde.org
Fri Oct 15 08:29:00 CEST 2010


On Friday 15. October 2010 07.46.26 Andre Somers wrote:
> The second option Scott gives is not as unsafe as it may sound, I think. 
> If you want, you could have your main thread do the network handling, 
> and only pass the QNetworkReply object pointers to the handling thread 
> after they have signalled their finished() signal. At that point, 
> QNetworkReply will not be accessed anymore by QNAM, so you can just have 
> your second thread access it and read its data, as long as your own code 
> for the main thread doesn't touch the reply anymore.

Scott suggested passing the data to the other thread, not the QNetworkReply 
object. There's a very important difference there.

QNR is created by QNAM and the two objects must be in the same thread as well, 
because of the sharing of internals (like the HTTP connection, cookie jar, 
etc.)

However, the QByteArray data blocks, once read, can be safely passed to other 
threads.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101015/d074056c/attachment.bin 


More information about the Qt-interest-old mailing list