Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7497663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:10:48+00:00 2026-05-29T19:10:48+00:00

Hi to all Qt Model/view programming gurus here in Stackoverflow. The project I am

  • 0

Hi to all Qt Model/view programming gurus here in Stackoverflow. The project I am working on requires me to define a QAbstractItemModel-derived model for XML data. I had previously asked a question here when I ran into a problem during implementation of this model:
QSortFilterProxyModel crashes when deleting a row from the source model via the source model function

The model is currently doing its job pretty well in the application except for some performance issues which I do not know how to solve. One of the functions in this
application is to add Frame element xml nodes by setting the Max Num and Rand numbers. Each Frame element will have both Num and Rand numbers running from 0 to MaxNum – 1 and 0 to MaxRand-1 respectively. Furthermore I will need to add a child Parameter element for Rand=0 th and Rand=MaxRand-1 th element each. An abbreviated illustration is as follows:

For Max Num=100, Max Rand=50

<Frame Num="0" Rand="0">
  <Parameter Value="false"/>
 </Frame>
 <Frame Num="0" Rand="1"/>
 <Frame Num="0" Rand="2"/>
 ...
 <Frame Num="0" Rand="48"/>
 <Frame Num="0" Rand="49">
  <Parameter Value="true"/>
 </Frame>
 <Frame Num="1" Rand="0">
  <Parameter Value="false"/>
 </Frame>
 <Frame Num="1" Rand="1"/>
 <Frame Num="1" Rand="2"/>
 ...
 <Frame Num="1" Rand="48"/>
 <Frame Num="1" Rand="49">
  <Parameter Value="true"/>
 </Frame> 
...
<Frame Num="99" Rand="0">
  <Parameter Value="false"/>
 </Frame>
 <Frame Num="99" Rand="1"/>
 <Frame Num="99" Rand="2"/>
 ...
 <Frame Num="99" Rand="48"/>
 <Frame Num="99" Rand="49">
  <Parameter Value="true"/>
 </Frame>

The application works fine when both MaxNum and MaxRand are small i.e. total number of Frame elements around 50. However, when the element count goes beyond 500 or so, the adding of Frame elements via QAbstractItemModel functions becomes painfully and exponentially slow. The GUI freezes for a long period of time, to the point where I gave up waiting most of the time.

MAJOR UPDATE:

I have found out what is causing the slowdown when inserting a large number of, say 1000 items into my model. I was calling both insertRow(row, parent) and setData() once per item inserted, which turns out to be very expensive due to the signals emitted inside these functions.

I have modified the code to insertRows(row, 1000, parent) instead and defined a new silentSetData() that does not emit a dataChanged(currIndex, currIndex). I have also included a new public function called notifyDataChanges(startRow, endRow, parentIndex) which in turns emit the dataChanged signal once for the given range of data. All is fine but now the caller class will need to explicitly call notifyDataChanges after the whole set of data is inserted.

Now I am wondering why is emitting dataChanged signals so expensive? Has anyone tried other means to overcome this problem when inserting/changing large number of items in the model at once?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T19:10:50+00:00Added an answer on May 29, 2026 at 7:10 pm

    Another way to do that is to explicitly reset the model data structures. For example in one of my models the data is represented with a QStringList. I have implemented a function that resets the data in the model. For example:

    void MyModel:setNewData(const QStringList newList) {
    
      beginResetModel();
    
      m_dataList = newList;
    
      endResetModel();
    }
    

    I would imagine this approach is also applicable in your case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having read all the StackOverflow entries regarding Model-View-ViewModel architecture along with most of the
We are trying to get the Model-View-Presenter pattern used on (virtually) all new dev
this is my core data model: I'm trying to get all LanguageEntries from a
I am writing an objective-c model to hold all of the data parsed from
I am using the Model-View-Presenter pattern in a WinForms project and one problem (among
I am working on my first programming project with no prior programming experience, so
Using Model->find('all') returns an array with the following structure: array( 0 => array('Model1' =>
If I have Model.objects.all() I want to get only one object for any content_object=foo,
When the .net 2.0 framework first came out, the provider model was all the
All, i have the following model defined, class header(models.Model): title = models.CharField(max_length = 255)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.