Results 1 to 9 of 9

Thread: GUI becomes unresponsive when adding more items to TreeModel

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2018
    Location
    India
    Posts
    34
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: GUI becomes unresponsive when adding more items to TreeModel

    Hi, a correction on the understanding. Its not 100 rows insertion at a time to the model.
    A single pair of beginInsertRows() and endInsertRows() with 1 row at a time. The entire insertion is happening in a loop of count 100.
    Is that the problem ?

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: GUI becomes unresponsive when adding more items to TreeModel

    Of course.
    Qt Code:
    1. beginInsertRows();
    2. Loop....
    3. endInsertRows();
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: GUI becomes unresponsive when adding more items to TreeModel

    Is that the problem ?
    As Lesiok said, yes, of course. What you are doing is forcing the UI to update with -every- new row. Do as he suggests - call beginInsertRows() with a row count of 100, add the rows to your internal model, then call endInsertRows() to update the UI.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  4. #4
    Join Date
    Jun 2018
    Location
    India
    Posts
    34
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: GUI becomes unresponsive when adding more items to TreeModel

    What will be the first and last index do I need to give in beginInsertRows() ,If I am trying to append 100 nodes to parent.

    Currently my code is

    beginInsertRows(parent, 0, 0);
    for ()
    {
    parentNode->AppendChild(child));
    }

    endInsertRows();

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: GUI becomes unresponsive when adding more items to TreeModel

    If I am trying to append 100 nodes to parent.
    Your code is incorrect. Read the documentation. QAbstractItemModel::beginInsertRows() explains it.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. QListWidget, help adding new items.
    By JeremyRussell in forum Newbie
    Replies: 4
    Last Post: 6th April 2011, 23:54
  2. Replies: 1
    Last Post: 4th February 2011, 01:41
  3. Adding new items to model (MVC)
    By Urvin in forum Qt Programming
    Replies: 1
    Last Post: 7th November 2010, 07:54
  4. QListView - adding items
    By creep33 in forum Qt Programming
    Replies: 3
    Last Post: 9th September 2010, 17:30
  5. adding items in qtablewidget
    By Djony in forum Qt Programming
    Replies: 17
    Last Post: 24th November 2006, 10:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.