Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QFileSystemModel setData problem
Forum Updated to NodeBB v4.3 + New Features

QFileSystemModel setData problem

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 680 Views
  • 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 Offline
    C Offline
    chabo
    wrote on last edited by
    #1

    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
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved