i am programming a file explorer and I am using a QFileSysteModel as the base.
I noticed that the methods QFileSystemModel::index()
and QFileSystemModel::fetchMore
causing the model to emit the signal rowsInserted
.
I have connected the rowsInserted
signal to a slot which sends data about new inserted rows. The problem is that the rows which comes from QFileSystemModel::index()
and QFileSystemModel::fetchMore
are not really new, but added to the model by the QFileSystemModel itself, which causes trouble in my program.
I tried so set flags before using QFileSystemModel::index()
and QFileSystemModel::fetchMore
but it was not reliable especially with the QFileSystemModel::fetchMore
.
Like:
m_blockRowInsert = true; // <-- blocks rowInserted for m_fileSysModel->index
auto index = m_fileSysModel->index(pathNew); // calls immediately rowsInserted
if(index.isValid())
{
if(m_fileSysModel->canFetchMore(index))
{
m_blockRowInsert = true;// <-- does not work reliable because rowsInserted can be called more than once by fetchmore
m_fileSysModel->fetchMore(index); // <-- calls rowsInserted after completing the function
}
}
I tried to reset the flag like this:
void onRowsInserted(const QModelIndex &parent, int first, int last)
{
if(m_blockRowInsert)
{
m_blockRowInsert = false;
return;
}
}