In my program, the users may 开发者_如何学Gochoose the directory to save their files or to modify some files in a specific directory. The program should give a warning if the users have no authorization to create a new file or to modify a file.
But I have no idea to implement the function except that I create a testing file. If the QFile::open(...) function returns true, I will understand the current user has access to write.
Is there any better idea to do that?
Use QFileSystemModel
class,it has method
QFile::Permissions QFileSystemModel::permissions ( const QModelIndex & index ) const
Request permissions for dir where you want to create files..
also, there are some tricks about permissions on windows - look into docs - they should be explicitly enabled in your app, and
QFile::ReadOwner
QFile::WriteOwner
QFile::ExeOwner
corresponds to current user
UPD - there is an easier way - just use
QString dirName=<your dir>;
QFileInfo f(dirName);
f.permissions ();
精彩评论