如何调用 dataChanged
以下是我添加的行类。它是由代码而不是表调用的,我希望它在添加新行时正确调用 dataChanged,尽管这不起作用,但表不执行任何操作。 我做错了什么?
void MyModel::add(const Person& p)
{
people.push_back(p);
QModelIndex top = createIndex(people.count() - 1, 0, 0);
QModelIndex bottom = createIndex(people.count() - 1, 3, 0);
emit dataChanged(top, bottom); // emit layoutChanged() if headers changed
}
The following is my add a row class. It is called by the code, not the table and I want it to properly call dataChanged when a new row is added, although this isn't working, the table doesn't do anything.
What am I doing wrong?
void MyModel::add(const Person& p)
{
people.push_back(p);
QModelIndex top = createIndex(people.count() - 1, 0, 0);
QModelIndex bottom = createIndex(people.count() - 1, 3, 0);
emit dataChanged(top, bottom); // emit layoutChanged() if headers changed
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
dataChanged
仅适用于现有数据,您需要调用beginInsertRows()
/endInsertRows()
应该可以。也许您甚至不需要
发出 dataChanged
dataChanged
works only on existing data, you need to callbeginInsertRows()
/endInsertRows()
That should work. May be you don't even need to
emit dataChanged