PDA

View Full Version : Update problem with QItemDelegate in QTreeView when adding rows



Valheru
12th June 2007, 16:02
I have a QItemDelegate set as the delegate for a column in a QTreeView. It's a progress bar showing the progress of threads that are running in the background downloading data. Now, I have a function that parses a file and adds the data to the QTreeView by adding a row to the QTreeView per parsed line in the file. Everything goes ok but for some STRANGE reason I can't isolate, the rows that are currently updating when the data is actually added freeze where they are and never update further. Subsequent rows that are processed by the threads are updated normally however.
I use the following code to update the progress :


void Knewz::updateDownloadProgress( QStandardItem* c, const int &progress )
{
int parent = c->parent()->row();
int child = c->row();
model->item( parent )->child( child, 3 )->setText( QString::number( progress ) );
bool ok;
int rows = model->item( parent )->rowCount();
int prog = 0;
int child_prog = 0;
int children = 0;

for( int i = 0; i < rows; ++i ){
child_prog = model->item( parent )->child( i, 3 )->text().toInt( &ok );

if( ok ){
prog += child_prog;
++children;
}

}

model->item( parent, 3 )->setText( QString::number( prog/rows ) );

}

wysota
12th June 2007, 17:07
Is it possible for you to provide something compilable? Could you also check if the model is updated and the problem is that the view doesn't refresh itself or the model doesn't update itself at all?

Valheru
12th June 2007, 18:23
I'll try hack something together by tomorrow. I had hoped that someone already knew this problem to be honest :)

I doubt that the the problem is that the view doesn't refresh itself - other progress bars carry on the very next instant. Since I'm downloading multipart files from a newsgroup over a 20 Mb connection, the progress bars go very fast since the multiparts are generally small. It's a freeze for the moment that the rows are appended to the model. I suspect that the model is turning off updating internally while the rows are being appended and it's in that time that the multiparts complete. Since they are finished by the time the model enables updating again, the download threads have already moved onto another row. But I shall try and provide something compileable, although it could be difficult. If you want, you can grab the code from svn trunk from sourceforge : https://knewz.svn.sourceforge.net/svnroot/knewz/trunk
I realize that it is a whole program and therefor not ideal to track this one specific problem, but I think it would be hard for me to code something artificial that could reproduce this problem.

/edit : you will need cmake and the kde4 libraries to compile this.