How to launch a QProcess with root rights?

守給你的承諾、 提交于 2019-11-30 16:23:18

I would strongly recommend finding a way to allow gphoto2 to be run with the logged in user's permissions. Perhaps this article has some helpful info.

If you have a distribution with sudo enabled, try to add "gksudo" to the command line of your process:

QString gphotoProgram = "gksudo /usr/bin/gphoto2"

If the user account is authorized as a sudo-er, it will ask the user password so that the program can run with root rights.

You can also use PolicyKit to start QProcess with sudo rights.

pkexec command

QString gphotoProgram = "pkexec /usr/bin/gphoto2";

Don't GNOME and KDE still have their own graphical sudo wrappers? (I'm a Windows guy myself.) You could use QProcess to launch "sudo" and let it take care of the elevation and subsequent gphoto launch.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!