QFileSystemModel setData problem
Unsolved
General and Desktop
-
Hi,
I would like to overwrite file/directory by rename if it already exists.My setData function:
bool MyModel::setData(const QModelIndex &idx, const QVariant &value, int role) { if (!idx.isValid() || idx.column() != 0 || role != Qt::EditRole || (flags(idx) & Qt::ItemIsEditable) == 0) { return false; } QString newName = value.toString(); QString oldName = idx.data().toString(); if (newName.isEmpty()) return false; if (newName == oldName) return true; if (newName.compare(oldName, Qt::CaseInsensitive)) { QModelIndex newIndex = index(filePath(parent(idx)) + QDir::separator() + newName); if (newIndex.isValid()) { remove(newIndex); } } return QFileSystemModel::setData(idx, value, role); }
After rename I've got two same elements in view.
Problem seems to be in QFileSystemModel::setData when trying to keep selection after renaming.
I am using Qt version 5.5
Can someone help me please?