Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Dialog UI freezed/unresponsive until all the elements are finished loading into my Qlistwidget. Any way to solve this?
Forum Updated to NodeBB v4.3 + New Features

Dialog UI freezed/unresponsive until all the elements are finished loading into my Qlistwidget. Any way to solve this?

Scheduled Pinned Locked Moved Unsolved General and Desktop
c++qt 5.4qdialogqlistwidgetthreads
2 Posts 2 Posters 530 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mr-Workalot
    wrote on 10 Aug 2020, 03:49 last edited by
    #1

    In my dialog i have qlistwidget and a "refresh-list" button, when i click refresh-list button this function

    Print_Descendants_key(exc.pUIAutomation, nullptr, 0);
    
    

    should run and it populates my qlistwidget with around 10000 items, but until this function prepares and adds 10000 items in my qlistwidget ,the UI remains frozen ,i am not able to see list-items being added sequentially but after a period of 2 mins of being unresponsive, it suddenly becomes perfectly responsive.

    How to tackle this ?? my desired effect is that,when this function is running , i should be able to see the elements adding up one-by-one/realtime in the QListwidget while the UI remains resonsive.

    Note (My try):- to acheive my desired effect, i have tried running that

    Print_Descendants_key(exc.pUIAutomation, nullptr, 0);
    

    function in a separate thread named "thread3" , and when i click refresh button, i was able to see the list-items being added in-front of me and the UI remained resposive, but i had a problem, when i clicked "Ok" ENTIRE UI CRASHES, i get errors in either qlist.h or abort.cpp

    The way i did it was like this---

    void Dialog::on_refreshbutton_clicked()
    {
        std::thread thread3(&KeyComd::Print_step,this);
        thread3.detach(); 
    }
    void KeyComd::Print_step()
    {
        Print_Descendants_key(exc.pUIAutomation, nullptr, 0);
    }
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 10 Aug 2020, 06:02 last edited by mrjj 8 Oct 2020, 06:14
      #2

      Hi
      10.000 items take some time to create and add.

      Print_Descendants_key must not touch/access the ListWidget from the other thread. that will not be good.

      To make the UI less hanged while adding such a number of items, you can do 3 things.

      1: use a View + custom model instead.
      If you already have all the data in a list/vector, a custom model on top of that would be super fast.
      2:
      Use a thread to send data to main. Make sure the thread is not hammering the
      main gui as that would lag too. You can also use a QTimer and simply slow down the adding.
      3:
      Do the ugly trick of calling QApplication::processEvents() (in the loop that adds the items)
      to allow the main GUI to be more responsive.

      1 Reply Last reply
      2

      2/2

      10 Aug 2020, 06:02

      • Login

      • Login or register to search.
      2 out of 2
      • First post
        2/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved