簡體   English   中英

在 Ubuntu 中以 root 用戶身份啟動 Qt 應用程序

[英]Launch Qt application as root user in Ubuntu

我正在測試一個基於 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM