
Originally Posted by
RolandHughes
I emailed several others and they conducted their own tests with their own code and got the same results. We didn't share any code.
Well, apparently you all got wrong results.
#include <QtGui>
public:
Model() {}
if(parent.isValid()) return 0;
return 1;
}
Q_UNUSED(index);
if(role
!= Qt
::DisplayRole) return QVariant();
qDebug() << Q_FUNC_INFO;
return "A";
}
};
int main(int argc, char **argv) {
Model model;
view.setModel(&model);
view.show();
return app.exec();
}
#include <QtGui>
class Model : public QAbstractTableModel {
public:
Model() {}
int rowCount(const QModelIndex &parent = QModelIndex()) const {
if(parent.isValid()) return 0;
return 1;
}
int columnCount(const QModelIndex &parent = QModelIndex()) const { return 1; }
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const {
Q_UNUSED(index);
if(role != Qt::DisplayRole) return QVariant();
qDebug() << Q_FUNC_INFO;
return "A";
}
};
int main(int argc, char **argv) {
QApplication app(argc, argv);
Model model;
QTableView view;
view.setModel(&model);
view.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
This test application clearly indicates there is no loop. If you want you can even disrupt the dataChanged() signal connection, modify the model and see that the view doesn't update until something else forces the view to ask explicitly for the item data.
I do agree though that the default table view and the default delegate read the model data more than one time. This is probably related to auto-sizing columns and rows but this is only my guess.
Bookmarks