gpt4 book ai didi

qt - 在 Ubuntu 中以 root 用户身份启动 Qt 应用程序

转载 作者:行者123 更新时间:2023-12-04 18:42:48 25 4
gpt4 key购买 nike

我正在测试一个基于 Qt 的 GUI 应用程序,它是在 Ubuntu 20.04 中使用 Qt creator 生成的。此应用程序使用一个需要 root 权限的库。然而,无法以 root 身份启动应用程序,因为它无法访问显示。
如果我以普通用户身份启动应用程序,我会在库中收到 modprobe 错误:

$ CGUTLGUI_Qt 
qt.core.qobject.connect: QObject::connect: No such signal QSignalMapper::mapped(int) in ../src/cgosfunc/cgosgpio.cpp:242
qt.core.qobject.connect: QObject::connect: (receiver name: 'CgosGPIO')
modprobe: ERROR: could not insert 'cgosdrv': Operation not permitted
如果我以 root 身份启动应用程序,它无法连接到显示器:
$ sudo CGUTLGUI_Qt 
No protocol specified
qt.qpa.xcb: could not connect to display :1
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vkkhrdisplay, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, xcb.
我只需要以一种或另一种方式运行程序,我不介意我不能修复这两个错误。以 root 身份启动 GUI 或以普通用户身份链接库都可以。

最佳答案

xhost 程序可用于允许其他用户或系统访问 X 显示器。
要允许 root 访问您的 X 服务器,请使用以下命令:

$ xhost local:root

关于qt - 在 Ubuntu 中以 root 用户身份启动 Qt 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69990038/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com