我正在尝试使用 ModelTest 调试我的模型(QAbstractItemModel)。我无法理解一个断言。
ModelTest 中有两个插槽可以拦截我的模型生成的信号。
- ModelTest::rowsAboutToBeInserted
- ModelTest::rowsInserted
插槽/功能 1 看起来像这样
void ModelTest::rowsAboutToBeInserted ( const QModelIndex &parent, int start, int end )
{
Changing c;
// ...
c.last = model->data ( model->index ( start - 1, 0, parent ) );
c.next = model->data ( model->index ( start, 0, parent ) );
insert.push ( c );
}
插槽 2 看起来像这样
void ModelTest::rowsInserted ( const QModelIndex & parent, int start, int end )
{
Changing c = insert.pop();
// other asserts ...
(*) Q_ASSERT ( c.next == model->data ( model->index ( end + 1, 0, c.parent ) ) );
}
我不明白 dla last 断言 (*)。让我们假设在我的应用程序中我添加了 1 行。此行是存储在我的模型中的唯一行。所以行号为0。
在我的模型中添加我调用的行之前
beginInsertRows(parentIndex, 0, 0);
那么为什么modeltest需要
模型->数据(模型->索引(开始,0,父))
等于
模型->数据(模型->索引(end + 1, 0, c.parent))
我在这里想念什么?请帮忙 :)