PDA

View Full Version : Letting a QThread take control over single items in a QWidget



replax
19th November 2010, 15:16
Hello,

at the moment i try to program a simple multithreaded internet search application. In the beginning, there is one QWidget with an input field and a push button. upon pressing the pushbutton, a new qwidget pops up containing two QWebViews, each of those searching for the same query, one through google and the other one through wikipedia.

The problem is the multithreading. I want to design it, so that each QWebView runs in its own thread using QThread, thus performing the rendering in different threads.
Now, how can i let a class deriving from QThread create a QWebView which will be displayed in another class's QWidget?

thank you for your time! if you need further information i am more than happy to share it with you!

yours sincerely
replax

high_flyer
19th November 2010, 15:40
I want to design it, so that each QWebView runs in its own thread using QThread, thus performing the rendering in different threads.
Doesn't work with Qt.
All GUI rendering must run in the main GUI thread.
You probably don't mean that however.
I guess you want the queries to be done in their own thread, not the rendering of the results.
But even that makes little sens to me.
Its not your application which is doing the search.
You application just waits for the results to the queries it sent, the searching is done in parallel by google and what ever other sites you sent your queries to, you only sit there and wait for the results.
So what do you need threads for?

replax
19th November 2010, 15:52
thanks for your quick reply!

yes, you are correct, my application just passes the queries and then recieves and displays the results from google etc.
i was trying to seperate the processing and rendering of the two qwebviews into threads to achieve a better performance when rendering more than one qwebview at the same time. it might not make sense, since the performance gain would be equal to zero, but my purpose behind all this was to learn more about qthreads and get familar with them before using threading in a bigger project.
so i guess it would not be possible without implenting threading in qwebview itself, which would be far too complicated for me.

high_flyer
19th November 2010, 16:17
Well, in general, you should use threads only for tasks that take long time, and you want to keep your gui resposive, and / or, when a sequential processing of several computation would take long, then you can process them in parallel.
But as you can see, in all the cases, you are not doing GUI in the threads, only data crunching.
So, using Qt with threads is really quite simple:
You cerate the object that encapsulates your work.
You move it to a thread.
You start the thread.
Somewhere else you wait for the thread finished signal.
Thats it.

Of course, this is a simple case, but it should cover most normal cases where threads are needed.