PDA

View Full Version : Adding threads to a Model-Proxy-View arrangement



brixton
7th December 2010, 23:43
Hi,
I have a program which is a QStandardItemModel connected to a QTableView through a QSortFilterProxyModel. I've subclassed the Model and the Proxy to perform filtering on the data, though all the actual computation occurs in the Model. In the future, I'm going to rewrite the Model to make it more efficient, basing it off the QAbstractItemModel so that I can use my own data structures.

So that's the background. What I would like to do is add a 'worker' thread in somewhere to get rid of the delay which occurs when the worker thread is processing large sets of data. If the user provides new input, the worker thread would stop and restart with the new input instead of finishing work which is useless.

My question is how should I add threaded support? I've read the docs and understand the concept of threads, but I'm unsure how I should organise the program.

Should I create a 'Worker' class which the QStandardItemModel will use?

Any suggestions will be appreciated! Thanks all.

Cucumber
8th December 2010, 02:59
Take a look at Mandelbrot example (http://doc.qt.nokia.com/latest/threads-mandelbrot.html).

brixton
9th December 2010, 17:22
Thanks Cucumber. The Mandelbrot example is a good one, but I'm more curious about working with threads and the model-view concept. Are there any examples of that out there I wonder?