如何以 root 权限启动 QProcess?

发布于 2024-10-31 18:49:38 字数 547 浏览 4 评论 0原文

我需要从 Qt 程序启动 gphoto2 。我这样做:

QString gphotoProgram = "/usr/bin/gphoto2";
QStringList gphotoArguments;
gphotoArguments << "--capture-image";
QProcess *gphotoProcess = new QProcess(this);
gphotoProcess->start(gphotoProgram, gphotoArguments);

但它永远不会以这种方式进入 Running 状态,因为 gphoto2 通常需要管理员权限才能在命令行上启动。

如何以适当的权限启动此 QProcess 以使 gphoto2 正常工作?

编辑:我明确指出,我希望用户不必输入密码,这意味着 gksudo、kdesudo 或任何其他图形解决方案对我来说都不是有效的选项。

I need to launch gphoto2 from a Qt program. I do this:

QString gphotoProgram = "/usr/bin/gphoto2";
QStringList gphotoArguments;
gphotoArguments << "--capture-image";
QProcess *gphotoProcess = new QProcess(this);
gphotoProcess->start(gphotoProgram, gphotoArguments);

but it never enters the Running state this way, as gphoto2 usually needs admin rights to be launched on command line.

How can I start this QProcess with proper rights to make gphoto2 working?

Edit: I precise that I would prefer the user to not have to enter a password, which means gksudo, kdesudo or any other graphical solution is not a valid option for me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

小镇女孩 2024-11-07 18:49:38

我强烈建议找到一种方法来允许 gphoto2 在登录用户的权限下运行。也许这篇文章 有一些有用的信息。

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.

柠檬 2024-11-07 18:49:38

如果您的发行版启用了 sudo,请尝试将“gksudo”添加到进程的命令行中:

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

如果用户帐户被授权为 sudo-er,它将询问用户密码,以便程序可以使用 root 权限运行。

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.

戴着白色围巾的女孩 2024-11-07 18:49:38

您还可以使用PolicyKit以sudo权限启动QProcess。

pkexec 命令

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

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

pkexec command

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

不即不离 2024-11-07 18:49:38

GNOME 和 KDE 是否仍然有自己的图形 sudo 包装器? (我自己就是 Windows 用户。)您可以使用 QProcess 启动“sudo”并让它处理海拔和随后的 gphoto 启动。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文