Qt Network: urls not loading
I have code as follows:
- void WebPageLoader::run()
- {
- networkManager->get(request);
- }
- }
The slot PageLoaded is never called. Is there something else one needs to do to get it working?
13 replies
As QNAM is asynchronous already, there is hardly any need to put it into a separate thread.
If you really need to use a thread, call exec() in your run method. This starts a local event loop and keeps the thread running until you call quit().
Be aware of the implications regarding object owners, signals and slots. Peppe has written a great wiki article on Threads, Events and QObjects [developer.qt.nokia.com], don’t miss to read it!
But the processing of the reply (my slot) is running in the main thread, or I’m I wrong?
To prevent the main thread from blocking while doing heavy processing in the reply-slot, QtConcurrent::run() [doc.qt.nokia.com] can be used. It will execute a function in a separate thread. This should of course be used together with QFutureWatcher.
I don’t know – if you did not put it into a separate thread, it runs in the main loop, yes. If the main thread is blocking depends on how much work is done in your slot. If it’s heavy-loaded, a separate thread can be a solution, but it has the drawback, that you cannot manipulate the GUI from it. You can send queued signals to slots of the GUI, though.
You must log in to post a reply. Not a member yet? Register here!




