Updating QListView from aggrigation thread make the GUI stuck
-
Hello all
I have simple application that build like this
Mainwindow hold QListView using QAbstractListModel
When I start the application I start single thread using thread worker
That its job is get data records from external web service , it gets 10 -20 records on each
Iteration .
Now the problematic part :
In the HttpAggrigator class that started from the thread worker
In the big while loop that iterate on each returned record
I emit signal to another class that called ViewControler and its job is populate To the QListView Model
In this part my window just freeze until all the items are set in the listview.
I checked with the profiling tool called "Sleepy" and indid in the ViewControler method that sets the items
Is cousing the slow down.
My question is how should I do it right so that item will be added in lightweight wayThe flow:
MainWindow -> start HttpAggrigator (in different thread )
HttpAggrigator -> get records -> start iterate them ( to fill data objects )
HttpAggrigator -> emit signal to ViewControler on each records iteration to build item into MainWindow QListView -
look at QCoreApplication::processEvents(), it is alot like doEvents() in visual basic (if you are familiar with it).
http://developer.qt.nokia.com/doc/qt-4.8/qcoreapplication.html#processEventsAlso, a recommendation. If an object is created in the mainwindow application, it should only be edited from the main window. So, instead of emiting the signal to slot in ViewController, do it in your main application. Or emit another signal from your ViewController, that slots to the mainwindow and updates the listview.
If your httpaggigator is in its own thread, then im assuming the population in the QListView is what is slowing it down.
Mainwindow->httpaggrigator
httpaggrigator->viewcontroller
viewcontroller->mainwindow (update listview).And in any while loops (which I am assuming is what is slowing down the gui), use QCoreApplication::processEvents() which will alow the form to update...
I could be misunderstanding how your using your classes, but this is Just a suggestion!