Nominate our 2022 Qt Champions!

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 way

    The 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).

    Also, 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.

    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!

  • where should i put the QCoreApplication::processEvents()
    i think you understand it right maybe should i also use beginInsertRows in the model?

Log in to reply