我有一个abstractTable模型,它有一个非常奇怪的问题。
rowCount方法;
int ordersModel::rowCount(const QModelIndex &) const
{
int i = oData->count();
qDebug() << "rowc=" << i;
return 711;
// return oData->count();
}当我硬编码值(711或更低的值)时有效,但如果我使用return i;或return oData->count();表不显示任何内容。(qDebug()报告数据有711个条目。
标题显示正确。我使用的是Qt 5.4.1,Windows 7。
难住了!
发布于 2017-06-06 20:07:43
试一试
int MyModel::rowCount(const QModelIndex &parent) const {
if ( parent.isValid() )
return 0;
return m_entryList.size();
}发布于 2017-06-06 21:50:35
您的问题可能与rowCount方法本身无关,尽管该方法也不正确-请参阅the other answer。模型实现的其他方面可能不会履行每个模型都必须履行的基本契约。
将发生以下一系列事件:
QAbstractItemModel.rowsInserted信号-它不调用beginInsertRows和endInsertRows。它已经破坏了它的contract.有关模型语义,请参阅the first section of this answer,并确保您理解它并遵循要求。
https://stackoverflow.com/questions/29740237
复制相似问题