PDA

View Full Version : Refresh TableModel



abbapatris
5th March 2008, 16:04
I have been trying to get a tableview and table model to work at a reasonable speed lately and it has failed. If I add 100 rows it takes about 14 seconds to refresh the view and forget about trying to scroll...every time I use the scrollbar it lags, skipping lines all over the place.

I tried to find what is taking so much of the systems resources, by putting qDebug()'s in my function and found that it calls the data() method continuously. It calls this method at least 5 times for each index and each role. Since I have 9 columns and there are seven roles it seems to call the method 31500 times then calls the header. It then starts over again without stopping. None of the data changes and I don't touch the screen while all this happening. It just keeps on calling data.

I hope what I wrote made some sense. If you could help that would be great.
My data method is something like this:

QVarient class::data(const QModelIndex &index, int role) const
{
if(!index.isValid())
return QVariant;
if(role == Qt:AlignmentRole)
return int(Qt::AlignRight | Qt::AlignVCenter);
else if(role == Qt::DisplayRole)
switch(index.column())
{
case 0: return 1;
case 1: return 1;
case 2: return 1;
case 3: return 1;
case 4: return 1;
case 5: return 1;
case 6: return 1;
case 7: return 1;
case 7: return 1;
}
}
else
return QVariant();
}

wysota
5th March 2008, 16:54
First of all try adding more than one row at a time by introducing custom methods to the model.

abbapatris
5th March 2008, 17:26
I use


beginInsertRows(row, count, QModelIndex)
{
then I populate my list
}
endInsertRows();

this way I can populate any number of rows

wysota
5th March 2008, 17:37
That's fine. Just make sure you don't call setData() afterwards :) I must say that with a model this size, your application should be very fast. So if you have a serveral seconds lag, you must be doing something wrong (either the model implementation is slow or you are using it in a slow way).

abbapatris
5th March 2008, 17:49
That is what I am thinking...I wish I could show you my code cause I am so stumped and so are my co-workers...but the code is not something I can show. :(

I am never even created setData. The View isn't editable, the new items come from a message on the backend. When I put the debug in the code it never stops calling the Data method though...it keeps calling that and also the setHeaderData.

wysota
5th March 2008, 19:07
Maybe you can show us code similar to your original one, but simpler and working on some other data?

abbapatris
5th March 2008, 19:26
I don't think I have time to write one that will do this and not be the same thing, cause I am on such a deadline right now. I basically barely have time to finish this :(

abbapatris
7th March 2008, 13:04
Hey, Thank you guys for trying to help. I did find out what was slowing my view down.
my data in my model were pointers in a list that was a pointer. So...

QList< item *> * itemlist;

I changed it to

QList<item> itemlist;

and it works fast

wysota
7th March 2008, 13:55
Hmm... really? Did it matter that much? I admit I'm surprised...