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.