1

I'm trying to run my Qt application as root on Linux.

import os
import sys
from PyQt6.QtWidgets import QApplication

from gui.gui import MainUI


if __name__ == '__main__':
    if os.getuid() != 0:
        args = ['pkexec'] + [sys.executable] + sys.argv
        os.execlp(args[0], *args)
    else:
        app = QApplication([])
        gui = MainUI()
        gui.show()
        app.exec()

MainUI is nothing but a QMainWindow with a QGridLayout in it. I haven't got around to adding any code to it, really. My error I get when running this code is a Qt error:

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: offscreen, minimal, minimalegl, linuxfb, eglfs, wayland, vnc, wayland-egl, xcb, vkkhrdisplay.

Any idea what's going on? I want to get it running as root before I add more code.

malonn
  • 59
  • 1
  • 7
  • Run this command `xhost local:root` in an active shell, and then try to run the program again as root. – musicamante Jul 07 '23 at 19:37
  • Yeah. I continued net searching, recalled Bleachbit, and found my way to the Arch Wiki. It seems running GUIs as root is not recommended. I will try a different method of running individual shell commands as root via the app to do what I want. This program could go public one day, and may as well be secure and follow guidelines. Thanks. – malonn Jul 07 '23 at 19:56
  • Yes, it's not recommended, but sometimes required (usually for strictly root-required aspects, such as drive/partition management, security configuration, etc. unless proper permissions are granted to the executable or the user). The real question is: what do you need this for? – musicamante Jul 07 '23 at 20:18
  • Just to do useless stuff in my root directory. Harmless stuff, but things that bug me. I know enough to not mess with risky things. I just get bitten by a bug to do things with my OS. Hey, my OS, right. I'm not violating any licenses. – malonn Jul 07 '23 at 21:57

0 Answers0