I want QNetworkAccessManager to run HTTP requests in seperate thread. Currently in QT4.6 it is running in the same thread and it causes my browser to hang.
This feature is recently introduced in QT 4.8 but now I cant switch to QT 4.8. therefore I want to implement this in QT 4.6 for QNetworkAccessManager .
Can anyone help me on this?
There are more than a couple ways to accomplish what you desire.
First, make sure you are using the QNetworkAccessManager correctly. By default HTTP requests, such as:
are made asynchronously, but this does not necessarily mean they are in their own thread. If you make a bunch of these calls, you could slow down the containing thread.
Now, one way that I use to ensure requests are made in separate threads is to create an entire QObject/QWidget for my QNetworkAccessManager like this:
(Header)
(Implementation)
Now you can make calls to your manager object from your main window’s implementation with calls like:
Once again, this is only one of the many methods you may use, and in some instances the QNetworkAccessManager will automatically place requests in their own thread. But this should force the operating system to place all of your requests in a thread separate from your main thread.