开发者

How to get information about the authorization of creating a new file or modifying a certain file in a specific directory?

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 ();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜