[Interest] QNetworkAccessManager

Thiago Macieira thiago.macieira at intel.com
Tue Aug 25 18:08:50 CEST 2015


On Tuesday 25 August 2015 08:54:35 Igor Mironchik wrote:
> Hi guys,
> 
> I created QNetworkAccessManager in a thread. Everything is fine but
> sometimes I received assertion that QCoreApplication can't send event to
> QNetworkAccessManager in another thread.
> 
> Is it Qt's bug? Or QnetwrokAccessManager couldn't be used in threaded
> environment?

It's most likely a bug in your code. Please provide the backtrace of the 
warning (run your application with QT_FATAL_WARNINGS=1) and we can help find 
where you've made a threading mistake.

QNetworkAccessManager can be used in a thread. But note that *all* uses of it 
and the QNetworkReply objects it creates need to be in that thread. You cannot 
access any of those objects from outside the thread. So you must have slots in 
that thread that do the reading from QNetworkReply and then pass on the 
QByteArray to the original thread.

With that in mind, I have to say: there's no advantage of using threads. 
You're just making your code more complex. You'll gain more by removing the 
threading.

> Is it possible to disable sending events from QCoreApplication to my
> network access manager?

No, it is not. The events in question are timer and socket activation events. 
If you disable them, QNetworkAccessManager will not receive anything from the 
network.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Interest mailing list