 Beginner
					
					
						Beginner
					
					
                                        
					
						
							
								 
							
						
					
					
						 
    
    
       
    
    
    
    
    
    
   
    
    
       
    
    
    
    
   Re: Too slow adding & defining items to QTreeWidget
 Re: Too slow adding & defining items to QTreeWidget
		 Beginner
					
					
						Beginner
					
					
                                        
					
						
							
								 
							
						
					
					
						 
    
    
       
    
    
    
    
    
    
   
    
    
       
    
    
    
    
   Re: Too slow adding & defining items to QTreeWidget
 Re: Too slow adding & defining items to QTreeWidget
		Well, I´ve made a custom Model and tried it with QTreeView and QTableView.
But both are still too slow even though my model is really simple.
In my application, I have like 8 columns in the view. I have to sniff network packets and print them in the view when I receive them. So, I am adding items to the view a lot of times, and each time I have to fill all the columns for each item added.
I really don't know anymore what to do. Will I have to implement a custom view too?
 Guru
					
					
						Guru
					
					
                                        
					
						
							
								 
							
						
					
					
						 
    
    
       
    
    
    
    
    
    
   
    
    
       
    
    
    
    
   Re: Too slow adding & defining items to QTreeWidget
 Re: Too slow adding & defining items to QTreeWidget
		How do you add items to the model? One cell at a time or whole rows/subtrees?
 Beginner
					
					
						Beginner
					
					
                                        
					
						
							
								 
							
						
					
					
						 
    
    
       
    
    
    
    
    
    
   
    
    
       
    
    
    
    
   Re: Too slow adding & defining items to QTreeWidget
 Re: Too slow adding & defining items to QTreeWidget
		Well, I made a class that stores the data for all the columns of a row.
I set all the texts for the entire row and after that I add the row to the model.
 
    
    
       
    
    
       
    
    
       
    
    
    
    
   
    
    
       
    
    
    
       
    
    
       
    
   Re: Too slow adding & defining items to QTreeWidget
 Re: Too slow adding & defining items to QTreeWidget
		Can we see the code?
 Beginner
					
					
						Beginner
					
					
                                        
					
						
							
								 
							
						
					
					
						 
    
    
       
    
    
    
    
    
    
   
    
    
       
    
    
    
    
   Re: Too slow adding & defining items to QTreeWidget
 Re: Too slow adding & defining items to QTreeWidget
		This is my method for adding one item( a row ) to the tableview:
Qt Code:
void AkViewItemModel::addItem(AkViewWidgetItem *newItem)
{
if(!newItem)
return;
int position = mItemsList.count();
newItem->mViewWidget = mHeaderItem->akViewWidget();
mItemsList.append(newItem);
endInsertRows();
}To copy to clipboard, switch view to plain text mode
And below is the method to add a list of items:
Qt Code:
void AkViewItemModel::addItems(QList<AkViewWidgetItem *> items)
{
int beginRow = mItemsList.count();
int numItems = items.count();
AkViewWidgetItem *item = NULL;
for(int i = 0; i < numItems; i++)
{
item = items[i];
item->mViewWidget = mHeaderItem->akViewWidget();
mItemsList.append(item);
}
endInsertRows();
}To copy to clipboard, switch view to plain text mode
When I add a lot of single items, it is really slow! But if I accumulate some items in my application and then add them through a list, it becomes a lot faster and solves my problem.
Why are these methods beginInsertRows and endInsertRows so slow?
 
    
    
       
    
    
       
    
    
       
    
    
    
    
   
    
    
       
    
    
    
       
    
    
       
    
   Re: Too slow adding & defining items to QTreeWidget
 Re: Too slow adding & defining items to QTreeWidget
		These methods are not slow. But they cause some signals to be emitted and each emition triggers a redraw of all the views displaying the model. So if you add 100 items a second then your application is busy refreshing the views. That's why it's better to accumulate changes and update the model in chunks.
Bookmarks