Launch Qt application as root user in Ubuntu

Viewed 485

I am testing a Qt-based GUI application, generated with Qt creator in Ubuntu 20.04. This application uses a library, for which root privileges are required. Nevertheless, it is not possible to launch the application as root, because it cannot access the display.

If I start the application as normal user I get a modprobe error on the library:

$ 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

If I start the application as root, it cannot connect to the display:

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

I just need to to run the program in one way or another, it doesn't mind if I cannot fix both error. It would be fine either to start the GUI as root or to link the library as normal user.

1 Answers

The xhost program can be used to allow other users or systems access to the X display.

To allow root to access your X server, use this command:

$ xhost local:root
Related