Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set file owner:group in Linux using Qt/C++

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?

like image 652
TSG Avatar asked Jan 19 '17 04:01

TSG


People also ask

How do you change file ownership permissions in Linux?

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.

What is QFile QT?

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().

How do I change root permissions in Linux?

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>.


1 Answers

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.

like image 147
trivelt Avatar answered Oct 26 '22 16:10

trivelt