Enabling Qt Widgets application to run with no gui capability (e. g. SSH) on Linux
-
When I run my Qt 6 widgets application in an SSH session on Linux, I get the following errors, and it doesn't run:
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, linuxfb, xcb, vnc, minimalegl, vkkhrdisplay, eglfs, minimal.
I know that obviously the GUI will not display or even run, and nothing GUI-related will work. That's fine. I would like to gracefully ignore this error and still run the app. If I know which condition to check, I may avoid calling
app.exec()
if that's a problem. Or, perhaps, there is a way to use another plugin, likeminimal
, as a stub to let the application work?In the worst case, I could check whether or not GUI is available and conditionally create either
QCoreApplication
orQApplication
. But I don't know how to write the check, any ideas? -
Hi,
If your remote machine has Xorg, you could enable X11 forwarding for your SSH connection.
Otherwise, you can use the offscreen plugin.
As for the availability check, it's possible but I currently don't remember how to implement it.
-
@SGaist, thank you!
I don't need forwarding, I just need Qt to ignore the problem. Ideally, a "no-op" plugin, so that no CPU cycles are wasted rendering off-screen either. How can I select a non-default plugin?And still, if I'm going to select it manually I do need to know whether or not I have the GUI capability. Please let me know if you remember the check - I tried googling, but nothing yet. Will give it another try.
-
You can use the QT_QPA_PLATFORM environment variable.
You can check this answer on the forum for inspiration.
-
Would it be sufficient for you to provide a command line option to turn off the GUI? In addition – not sure if would work – you could register your own function with
atexit
(is in the C standard) that prints a help message that you could try running with your parameter for no-GUI (which hopefully shows up after the error message from Qt).On Linux it could also help to check if the
DISPLAY
environment variable is set. This is not the case (by default) for SSH connections without X forwarding. -
Good suggestions, thanks!