How to set permissions to a file using QFile::setPermissions()
Hi, everybody. I have a problem when working with file permissions. When I create a file, its default permissions are -rw-r--r-- and now i want to add execute permission to this file. This mean its permissions must be -rwxr-xr-x. So I used these commands:
Code:
myfile.
setPermissions(QFile::ExeGroup);
myfile.
setPermissions(QFile::ExeOther);
myfile.
setPermissions(QFile::ExeOwner);
myfile.
setPermissions(QFile::ExeUser);
But it doesnt work. May you help me find a solution for this. Thank you very much.
Re: How to set permissions to a file using QFile::setPermissions()
What is happening is that you are overwriting the permissions not adding to them so what you have here:
Code:
myfile.
setPermissions(QFile::ExeGroup);
myfile.
setPermissions(QFile::ExeOther);
myfile.
setPermissions(QFile::ExeOwner);
myfile.
setPermissions(QFile::ExeUser);
should look like this:
so that you apply all of the permissions at the same time.
Re: How to set permissions to a file using QFile::setPermissions()
thank you for your supply, but your suggest doesnt work to. I have changed my code like this:
Code:
if(!myfile.
setPermissions(QFile::ReadOwner|QFile
::WriteOwner|QFile
::ExeOwner|QFile
::ReadGroup|QFile
::ExeGroup|QFile
::ReadOther|QFile
::ExeOther)) {
qDebug("Something wrong!");
}
return;
out << preview;
myfile.close();
But it doesnt work. So i guess it is not beacause the ORed statement. Could you please show me how?
I read the Qt help, but couldnt find any thing could help.
Thank you very much.
Re: How to set permissions to a file using QFile::setPermissions()
Where exactly is it failing? is it prematurely returning or are you getting your qdebug() message saying something is wrong?
Re: How to set permissions to a file using QFile::setPermissions()
Ok. this problem was solved. thank you very much. A friend of mine tell me the wrong in my code. just put the if statement below the open file command. Thanks.