这个简单片段的执行:
{
QModelIndexList sel = ui->tableView->selectionModel()->selectedRows(0);
sel.at(0).isValid(); // To prevent removing the previous line by optimization
}
takes more than 30 seconds when the number of selected rows is about one million. QModelIndex 列表的构建几乎是立即的,但销毁需要永远。时间花在这个函数上:
template <typename T>
Q_INLINE_TEMPLATE void QList<T>::node_destruct(Node *from, Node *to)
{
if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic)
while(from != to) --to, delete reinterpret_cast<T*>(to->v);
else if (QTypeInfo<T>::isComplex)
while (from != to) --to, reinterpret_cast<T*>(to)->~T();
}
有人有解决方案吗?有什么方法可以在不创建的情况下获取所选行的索引QModelIndexList
,或者我可以以某种方式加速销毁?