Is there a way to update a file's permissions in QFileSystemModel (c++)? Prior to allowing a user to rename a file listed in the model using a qtreeview, I make sure the file gets checked out of source control. At this point the file is no longer read only, but the model still believes it's read only. How can I force the model to update a file's permissions without losing the expand / collapse state of the tree?
Thanks!
Update: The file is already flagged as writeable after checking out the file. The Model remains unaware of the change though.
QFile file(path.c_str());
QFileDevice::Permissions perms = file.permissions();
if (perms & QFile::WriteUser)
{
// Is already true
}
Just to be sure, I went ahead and used
file.setPermissions(file.permissions() | QFile::WriteUser);
with no luck changing the permissions reported for that file in the model.
Update:
int perms = fsModel->data(index, QFileSystemModel::Roles::FilePermissions).value<int>();
if (perms & QFile::WriteUser)
{
int i = 0;
}
Note: the above permissions never has the QFile::WriteUser flag set unless the file was writeable before the model was created.
setRootPath() is the key to solving this as well. It seems that you have to call it twice to get it to update the read only permissions. I stumbled across this when I changed my selection code to call:
everytime an item was selected. Then when I doubleclicked an item, I saw the icon change to checked out. Granted it didn't immediately let me rename it, I had to double click it again, but it does work.
My Process:
Connect to the OnBeginEdit() signal and checkout the file / change permissions
When an item is selected:
Inside OnBeginEdit()
Do the following TWICE if you didn't set the path to the current folder when the item was selected
Keep in mind you will have to doubleclick twice or press F2 twice - once to checkout and second to actually change the file.