PDA

View Full Version : converting permission numeric code to rwx format



rahulvishwakarma
25th October 2023, 08:51
I have a form having a list widget and a label. I want to display file permission, when I click listwidget having file names got from some filesystem. I used following code :



QFile file(strpath);
QFileDevice::Permissions p = file.permissions();
labelpermission->setText(QString::number(p));

in help manual I got following :-


QFileDevice::ReadOwner 0x4000 The file is readable by the owner of the file.
QFileDevice::WriteOwner 0x2000 The file is writable by the owner of the file.
QFileDevice::ExeOwner 0x1000 The file is executable by the owner of the file.
QFileDevice::ReadUser 0x0400 The file is readable by the user.
QFileDevice::WriteUser 0x0200 The file is writable by the user.
QFileDevice::ExeUser 0x0100 The file is executable by the user.
QFileDevice::ReadGroup 0x0040 The file is readable by the group.
QFileDevice::WriteGroup 0x0020 The file is writable by the group.
QFileDevice::ExeGroup 0x0010 The file is executable by the group.
QFileDevice::ReadOther 0x0004 The file is readable by anyone.
QFileDevice::WriteOther 0x0002 The file is writable by anyone.
QFileDevice::ExeOther 0x0001 The file is executable by anyone.

and when I was in exicuting program prmission was displayed as : 21845 ( for /bin/GET ) or 30581 (for /home/rahul/.netbeans).
Now I want to display this numeric code in form of "drwxr-xr-x" format. But here is only four fields and in numeric code there are five fields.
So my question is how to decode this numeric code to rwx code and display in QLabel.

Ginsengelf
26th October 2023, 07:16
Hi, I think you are mixing decimal and hexadecimal numbers. For example 30581 is decimal (base 10). In hex (base 16) it is displayed 0x7775, and that can easily be matched to the QFileDevice numbers like ReadOwner.

Ginsengelf