Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QFileSystemModel setData problem

    General and Desktop
    1
    1
    523
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      chabo last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • First post
        Last post