I need to change the owner and group of a file under Linux using Qt 5.7 /C++. I found the QFileInfo::ownerID
and QFileInfo::groupID
getters, but there appear to be no setters for these values.
I need the Qt equivalent of chown.
Is there a way to set these values using Qt functions?
To change file and directory permissions, use the command chmod (change mode). The owner of a file can change the permissions for user ( u ), group ( g ), or others ( o ) by adding ( + ) or subtracting ( - ) the read, write, and execute permissions.
QFile is an I/O device for reading and writing text and binary files and resources. A QFile may be used by itself or, more conveniently, with a QTextStream or QDataStream. The file name is usually passed in the constructor, but it can be set at any time using setFileName().
As with chown, and chgrp, only the owner of a file or the superuser (root) can change the permissions of a file. To change the permissions on the file, type chmod, how you want to change the permissions, the name of the file, then press <Enter>.
Setting file permissions can be done by QFile::setPermissions method instead of using native chmod function, but Qt has not equivalent of chown. You should use chown()
function from unistd.h
Look here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With