QThreadPool , QRunnable and objects that need to be created in main thread
Hi everyone. I'm struggling for a few hours to fix a problem I'm currently facing.
The problem started with the impossibility to create QWebPage in a separate thread other than main thread(GUI thread): "QWebPage in a different thread":http://developer.qt.nokia.com/forums/viewthread/6425
Looking further into the problem I realize that QWebPage has some QWidget dependencies so.. I said ok I can't create this in a separate thread.
My application is using a QThreadPool with 10 threads. For every thread I need to create a QWebPage object and loads some html pages.
Solutions I can think of:
- create all QWebPage objects in main thread and use singal/slot implementation to communicate with the thread.
- use moveToThread to move the QWebPage object to the thread after has been created on main thread.
This are those 2 solutions, however I'm facing some problem/questions:
For solution #1 : if I'm creating all QWebPage objects in main thread and call them in the main thread what will be the purpose of using threads. wouldn't this be a single thread solution?
For solution #2 : how can I move the QWebPage to a thread using moveToThread method if I don't know to what thread to move it(I'm using QThreadPool and I don't have(or at least at I don't know) how can I access a certain QThread that will handle a QRunnable currently in queue and waiting pe be executed?
If you know other solutions, or how to implement those current solution I'll appreciate you're help.
You can't move QWebPage to other threads. It uses GUI elements and it must live in the main thread.