Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Error QXcbConnection: Could not connect to display :0
Forum Updated to NodeBB v4.3 + New Features

Error QXcbConnection: Could not connect to display :0

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 364 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mykhailo_88
    wrote on last edited by
    #1

    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.

    JonBJ 1 Reply Last reply
    0
    • M Mykhailo_88

      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.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @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??

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mykhailo_88
        wrote on last edited by Mykhailo_88
        #3

        @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
        
        JonBJ 1 Reply Last reply
        0
        • M Mykhailo_88

          @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
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @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 your

          QXcbConnection: 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,

          M 1 Reply Last reply
          0
          • JonBJ JonB

            @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 your

            QXcbConnection: 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,

            M Offline
            M Offline
            Mykhailo_88
            wrote on last edited by
            #5

            @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, using DBus?

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved