Solved QAbstractTableModel run data() several times even if there are no modifications
-
@JonB I'm sure that is the several times that data() is called, because It never stop of being called. And if I hide the QTableView everything works fine.
-
@jsulm thanks, I will show how to use it
-
@JonexElectronic said in QAbstractTableModel run data() several times even if there are no modifications:
@JonB I'm sure that is the several times that data() is called, because It never stop of being called. And if I hide the QTableView everything works fine.
Don't know what you mean. I never said
data()
was not called, I said it is called as you show, and seemingly takes 0.1 seconds.I do not believe "it never stop being called". Once the table has been drawn if you do not move the mouse or otherwise interact it should not be being called. Else you have something wrong in your code. Note that if you use the debugger and place breakpoints it may get called, because debugging causes the application to repeatedly gain & lose focus.
-
data()
will be called anytime it needs to repaint (so passing the mouse over it probably triggers it). What you could do is use aQCache<quint64,QVariant>
to store previous result and return them without fetching them again (the key would be something like:(static_cast<quint64>(index.column()) << 32) | static_cast<quint64>(index.row())
) -
@JonB No, it is done 10 times every 0.001 sec.
QTime("10:31:01.419")
QTime("hh:mm:sec.ms")
Probably I have something wrong. Believe me, it is always being called . -
@VRonin I'm not sure how to do that. Could you give me an example?
-
@JonexElectronic said in QAbstractTableModel run data() several times even if there are no modifications:
@JonB No, it is done 10 times every 0.001 sec
I don't know what you mean. You chose to show some
QTime
outputs, and they range fromQTime("10:31:01.419")
toQTime("10:31:01.510")
, which is 0.1 seconds. If you meant anything other than that it is not shown. That's all I can say, and never mind.Probably I have something wrong. Believe me, it is always being called .
I asked you to
Once the table has been drawn if you do not move the mouse or otherwise interact it should not be being called.
So let it draw. Take your hands of the keyboard and the mouse. Sit there and do nothing. Is
data()
still being called regularly, yes or no? -
I took my hands off and It happend. Still being called.
-
@JonexElectronic
Then it sounds like something else is going on, and you need to discover what.Why don't you start by commenting everything out in your
data()
and replacing it by, say:QVariant XfTableModelQlist::data(const QModelIndex &index, int role) const { qDebug()<<" IndexColum = "<< index.column() << " IndexRow = " << index.row() << " IndexRole = " << role; if (role==Qt::DisplayRole) return "Hello" return QVariant(); }
Does it still get called repeatedly now?
-
@JonB said in QAbstractTableModel run data() several times even if there are no modifications:
QVariant XfTableModelQlist::data(const QModelIndex &index, int role) const
{
qDebug()<<" IndexColum = "<< index.column() << " IndexRow = " << index.row() << " IndexRole = " << role;
if (role==Qt::DisplayRole)
return "Hello"
return QVariant();
}Yes it is... My tableView is in a QDockWidget and share the windows with others QDockWidget in the same QMainWindow. It could be the problem?
-
@JonexElectronic
That I would not know. Are you able perhaps to test it outside of a dock widget? But if something is constantly calling yourdata()
method when you are not doing anything at all that is clearly a problem. -
@JonB Yes, I have tried it and it does not happen again. Thanks, probably is something that emit a signal to repaint all de Dock? Is it
posible?? -
@JonexElectronic said in QAbstractTableModel run data() several times even if there are no modifications:
Thanks, probably is something that emit a signal to repaint all de Dock? Is it
posible??Again, sorry, not my area. But if something calls for a repaint/update of a view onto your model you would indeed see the model's
data()
method being called many times.You need someone else to comment on your currently reported situation with
data()
being called repeatedly on your dock widget, as this needs not to be happening.