Error QXcbConnection: Could not connect to display :0
-
Hello everyone,
Problem:
I have an application consisting of two components: a service and a client. The service is responsible for launching the client using QProcess::startDetached. The issue occurs when I start the application from Wayland, log out, and then log in again to a new session. After that, the service starts as expected, but the client only runs for a moment and then displays the following log message:QXcbConnection: Could not connect to display :0
Only restarting the service helps🥲
Environment Details:
- OS: Ubuntu 24.04.1
- Display server: Wayland
- Qt5
- Command to check $DISPLAY:
echo $DISPLAY :0
Question: what can it be? Perhaps the service is launched by the client before Xwayland is configured? I remind you that this happens only on Wayland and after Log out.
-
@Mykhailo_88 said in Error QXcbConnection: Could not connect to display :0:
The service is responsible for launching the client using QProcess::startDetached.
Then why would you expect the client to have any access to a display? I would not. Services do/should not have a display, anything they spawn should be in same situation. Why do you launch a client from a service? Normally a service runs in background, if you have interactive clients you launch them yourself from the desktop and let them connect to service (e.g. socket).
If per chance your client is not supposed to be interactive then don't make it a
QGuiApplication
.Furthermore: if you say you are running under Wayland why would you get a
QXcbConnection
error?? Does not sound like Wayland to me, sounds like X11. Is the client so confused being launched that it thinks you are Xcb when you say you are actually Wayland?? -
@JonB Hello, thank you for your response.
The service was specifically created to launch a client with a GUI and communicate with it via QLocalSocket. The service starts automatically because it has a .desktop file. As I understand it, this was designed for future multi-session work (one service with multiple clients).However, I don’t understand why this doesn’t work specifically on Wayland and specifically after log out. On Xorg, everything works fine.
And yes, this is indeed Wayland:
~ ❯ echo $XDG_SESSION_TYPE wayland
-
@Mykhailo_88
I will have to take your word about the way you have a service which launches a desktop client. I don't really understand because services usually start at system startup and you don't have, and don't know whether you will have, any interactive desktop. But there you are.For Wayland itself I had to give up on it under Ubuntu 24.04. Too many bugs, too many restrictions, too many applications going wrong (both Qt ones and non-Qt ones such as MySQL Workbench). I have had ton revert to making desktop run under X11.
I also had a case where when I did run under Wayland it did not work right initially and I had to log out and log back on again to make it work. Kind of the opposite way round from you. That might have been for MySQL Workbench, I can't recall. Whichever, I only had more problems with Wayland than X. YMMV.
Finally, you show
echo $XDG_SESSION_TYPE
but that is from a prompt and is at some time after the Qt child was spawned. This does not prove what it was, in the child process, at that time. I stand to be corrected by an expert here [actually, could someone kindly confirm or deny this?], but so far as I know yourQXcbConnection: Could not connect to display :0
can only mean Qt program was trying to use X11/Xorg/Xcb and not Wayland at that time. Maybe you could try explicitly passing the environment variable or command line option for Wayland to the child to see whether that makes any difference to that message,
-
@JonB My service launches the client almost immediately after the user logs in; it seems this is determined using
DBus
. I tried running the client from the terminal, and everything works. Maybe I should change the method of launching the client, for example, usingDBus
?