Ubuntu – Why pkexec does not launch Qt-based application as root user

20.04kubuntupkexecqtsudo

Previously it was told that it is bad idea to use sudo to launch GUI-based applications.
So one should use pkexec instead.

I remembered it, so I tried this to launch Kubuntu Driver Manager on Kubuntu 20.04 LTS using terminal as

pkexec kubuntu-driver-manager

But this command does not work, it crashes with the following output:

qt.qpa.xcb: could not connect to display
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: wayland-org.kde.kwin.qpa, dxcb, eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, xcb.

Aborted (core dumped)

I have recently reported bug 1885615. But I'm very surprised with this behavior. And what is interesting sudo kubuntu-driver-manager works normally.
I still can launch Gtk-based applications on Kubuntu using pkexec – commands like pkexec pluma results in opening the application with root rights.

So my question is in the title.

Best Answer

To launch a program with pkexec a proper .policy file for that program needs to be present in the /usr/share/polkit-1/actions directory. It has nothing to do with which graphical toolkit (Gtk or Qt) is used.

Related Question