How to get authorization information for creating a new file or changing a specific file in a specific directory?

In my program, users can select a directory to save their files or to change some files in a specific directory. The program should issue a warning if users do not have the right to create a new file or modify the file.

But I have no idea to implement the function, except that I am creating a testing file. If the QFile :: open (...) function returns true, I will understand that the current user has write access.

Is there any better idea for this?

+4
source share
1 answer

Use the QFileSystemModel class, it has a method

 QFile::Permissions QFileSystemModel::permissions ( const QModelIndex & index ) const 

Request permissions for the directory where you want to create files.

there are also some tricks about window permissions - look docs - they should be explicitly included in your application and

 QFile::ReadOwner QFile::WriteOwner QFile::ExeOwner 

matches current user

UPD - there is an easier way - just use

 QString dirName=<your dir>; QFileInfo f(dirName); f.permissions (); 
+1
source

All Articles