アイテムから特定の子を削除したいのですが、親アイテムは const です。別の親アイテムに置き換えることはできません。私が持っているもので作業する必要があります。子アイテムには、それ自体で複数のレベルの子があります。私はこれを試しましたが、うまくいきません。
QStringList list; // contains list of names that should be deleted
for(int row=0; row < parent->rowCount(); ++row)
{
QStandardItem* child = parent->child(row);
bool found = 0;
for(size_t i = 0; i<list.size(); ++i)
{
if(list[i] == child->text()) // check if child should be removed
{
found = 1;
break;
}
}
if(!found)
{
parent->removeRow(row); // this breaks child ordering for next iteration
}
}
正しく行うにはどうすればよいですか?前もって感謝します。