PDA

View Full Version : Running QSortFilterProxyModel outside of the GUI thread to speed things up?



willjones
20th January 2012, 17:21
I've got a QAbstractItemModel being displayed in a QTreeView, and I'm filtering it using QSortFilterProxyModel.

For the most part, things work okay, but the filtering is agonizingly slow. This in itself would be fine if I could just put up an hourglass and let the user know that the search is running, but the problem is that it's freezing up the whole GUI while the search is running.

Is there any way to run the QSortFilterProxyModel outside of the GUI thread to avoid this problem, and then have the GUI update when the filtering is complete?

amleto
20th January 2012, 18:25
I dont know, but it should be easy to test. Just make a QThread, start() it, and move the sort proxy to that thread. Bear in mind that only the proxy's slots will run in the new thread

wysota
20th January 2012, 18:43
Moving the proxy model to an external thread just like that is not going to work.

It's possible to do filtering in another thread but it requires much more work and QSortFilterProxyModel will be of little (if any) use here. One needs to trigger filtering, make a snapshot of the model, do the filtering in another thread and when it is done, update the proxy model with results of this operation. Alternative approach would be to use a 0-timeout timer to test consecutive rows for the filtering condition and if match is found, filter the item out in the proxy (without any extra threads). Both there approaches would not use QSortFilterProxyModel.