I’m developing an application to track online Xbox Live, PSN, and Steam friends. The application performs a series of QNetworkRequests using a QNetworkAccessManager. The Xbox Live and PSN code use a QWebView to simulate a browser environment. The requests are performed correctly, but it slows down the main GUI thread until each request is finished.
Here’s some example code:
void Steam::fetchFriends(QString username)
{
QNetworkRequest userXml("http://steamcommunity.com/id/" + username + "/friends/?xml=1");
m_nam->get(userXml);
}
I’ve created a signal to tell the GUI that friends have been downloaded and processed. Then the friends list is updated in the GUI. Some of my other code is more complex and it’s possible that I need to move the processing code to another thread.
Can someone confirm that QNetworkAccessManager and QNetworkRequest are multithreaded or if they should be moved into separate threads?
QNetworkAccessManageris not threaded in its implementation. It is asynchronous and uses the event loop.Those who claim they have needed to use it in a threaded state for performance reasons have noted that they need to create the instance specifically in the thread, and not try and move it to a thread. Here is a link to someone posting an example of such.
Before creating it in a separate thread, be sure first that you aren’t doing any blocking operations that might cause the main thread to slow down.