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. qt.qpa.xcb: could not connect to display
Forum Updated to NodeBB v4.3 + New Features

qt.qpa.xcb: could not connect to display

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 801 Views 1 Watching
  • 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.
  • O Offline
    O Offline
    overfl0w
    wrote on last edited by
    #1

    Failing to start QT5 application from a privileged process. The application starts normally if it is started from a bash shell.

    To be more precise, we are using AWS Greengrass Edge runtime environment that runs "components" (apps, that can be any language). We have a service script that usually starts the QT5 application when the environment initially boots. The service script is the following:

    #!/bin/sh
    
    if test -z "$XDG_RUNTIME_DIR"; then
        export XDG_RUNTIME_DIR=/run/user/`id -u`
        if ! test -d "$XDG_RUNTIME_DIR"; then
            mkdir --parents $XDG_RUNTIME_DIR
            chmod 0700 $XDG_RUNTIME_DIR
        fi
    fi
    # wait for weston
    while [ ! -e  $XDG_RUNTIME_DIR/wayland-0 ] ; do sleep 0.1; done
    sleep 1
    cd
    
    until pids=$(pidof weston)
    do   
        sleep 1
    done
    
    echo "Starting Dash Display"
    export QT_DEBUG_PLUGINS=1 
    QT_IM_MODULE=qtvirtualkeyboard /usr/bin/dashV3 --fullscreen &
    unset QT_DEBUG_PLUGINS
    

    NOTE: I've done the QT_DEBUG_PLUGINS=1 to see the output, and it fails when it attempts to load xcb plugin:

    Got keys from plugin meta data ("xcb").
    QFactoryLoader::QFactoryLoader() checking directory path "/usr/bin/platforms"
    loaded library "/usr/lib/plugins/platforms/libqxcb.so".
    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..
    

    If I run the application normally in an opened bash environment, it spins it up, loading up all of the plugins available, but when ran within another process (in a privilege mode, from Greengrass runtime environment, which is still ROOT privilege uid/gid of 0), it fails about the 3rd of 4th plugin loading (XCB)

    (I've omitted the other plugins as part of the QT_DEBUG_PLUGINS=1, since the logs in Greengrass environment come out funny prefixed and suffixed with Greengrass-specific log format, and it is notoriously hard for me to "edit" it).

    I guess, the key question is: why does it run normally when the same command is ran from BASH, but fails on the above, when another process kicks it off.

    I thought I'd provide some additional details, how the script is run, from Greengrass component (via, what they call "recipes"):

    RecipeFormatVersion: "2020-01-25"
    ComponentName: "{COMPONENT_NAME}"
    ComponentVersion: "{COMPONENT_VERSION}"
    ComponentDescription: "Savic MC Dash App"
    ComponentPublisher: "{COMPONENT_AUTHOR}"
    Manifests:
      - Platform:
          os: linux
        Lifecycle:
          Run:
            RequiresPrivilege: true
            script: bash {artifacts:decompressedPath}/Dash/run.sh
        Artifacts:
          - URI: "s3://BUCKET_NAME/COMPONENT_NAME/COMPONENT_VERSION/Dash.zip"
            Unarchive: ZIP
            Permission:
              Execute: OWNER
    

    The key thing here to note is:

    Run:
            RequiresPrivilege: true
            script: bash {artifacts:decompressedPath}/Dash/run.sh
    

    Nothing special about this part of the config, other than it tells Greengrass to run run.sh as root.

    Are there some env variables that may be missing?
    Do I need to run it in some other "mode"?

    Thanks for your help.

    Additional notes:
    The OS that our QT5 runs on is YOCTO Linux (Embedded Linux), on a Toradex IMX8 board.

    The reason why we've moved from running it as a system process, to a Greengrass runtime environment is that Greengrass has an entire ecosystem surrounding over-the-air updates, lifecycle management of apps/components/services, visibility, access to MQTT etc. etc.

    jsulmJ 1 Reply Last reply
    0
    • O overfl0w

      Failing to start QT5 application from a privileged process. The application starts normally if it is started from a bash shell.

      To be more precise, we are using AWS Greengrass Edge runtime environment that runs "components" (apps, that can be any language). We have a service script that usually starts the QT5 application when the environment initially boots. The service script is the following:

      #!/bin/sh
      
      if test -z "$XDG_RUNTIME_DIR"; then
          export XDG_RUNTIME_DIR=/run/user/`id -u`
          if ! test -d "$XDG_RUNTIME_DIR"; then
              mkdir --parents $XDG_RUNTIME_DIR
              chmod 0700 $XDG_RUNTIME_DIR
          fi
      fi
      # wait for weston
      while [ ! -e  $XDG_RUNTIME_DIR/wayland-0 ] ; do sleep 0.1; done
      sleep 1
      cd
      
      until pids=$(pidof weston)
      do   
          sleep 1
      done
      
      echo "Starting Dash Display"
      export QT_DEBUG_PLUGINS=1 
      QT_IM_MODULE=qtvirtualkeyboard /usr/bin/dashV3 --fullscreen &
      unset QT_DEBUG_PLUGINS
      

      NOTE: I've done the QT_DEBUG_PLUGINS=1 to see the output, and it fails when it attempts to load xcb plugin:

      Got keys from plugin meta data ("xcb").
      QFactoryLoader::QFactoryLoader() checking directory path "/usr/bin/platforms"
      loaded library "/usr/lib/plugins/platforms/libqxcb.so".
      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..
      

      If I run the application normally in an opened bash environment, it spins it up, loading up all of the plugins available, but when ran within another process (in a privilege mode, from Greengrass runtime environment, which is still ROOT privilege uid/gid of 0), it fails about the 3rd of 4th plugin loading (XCB)

      (I've omitted the other plugins as part of the QT_DEBUG_PLUGINS=1, since the logs in Greengrass environment come out funny prefixed and suffixed with Greengrass-specific log format, and it is notoriously hard for me to "edit" it).

      I guess, the key question is: why does it run normally when the same command is ran from BASH, but fails on the above, when another process kicks it off.

      I thought I'd provide some additional details, how the script is run, from Greengrass component (via, what they call "recipes"):

      RecipeFormatVersion: "2020-01-25"
      ComponentName: "{COMPONENT_NAME}"
      ComponentVersion: "{COMPONENT_VERSION}"
      ComponentDescription: "Savic MC Dash App"
      ComponentPublisher: "{COMPONENT_AUTHOR}"
      Manifests:
        - Platform:
            os: linux
          Lifecycle:
            Run:
              RequiresPrivilege: true
              script: bash {artifacts:decompressedPath}/Dash/run.sh
          Artifacts:
            - URI: "s3://BUCKET_NAME/COMPONENT_NAME/COMPONENT_VERSION/Dash.zip"
              Unarchive: ZIP
              Permission:
                Execute: OWNER
      

      The key thing here to note is:

      Run:
              RequiresPrivilege: true
              script: bash {artifacts:decompressedPath}/Dash/run.sh
      

      Nothing special about this part of the config, other than it tells Greengrass to run run.sh as root.

      Are there some env variables that may be missing?
      Do I need to run it in some other "mode"?

      Thanks for your help.

      Additional notes:
      The OS that our QT5 runs on is YOCTO Linux (Embedded Linux), on a Toradex IMX8 board.

      The reason why we've moved from running it as a system process, to a Greengrass runtime environment is that Greengrass has an entire ecosystem surrounding over-the-air updates, lifecycle management of apps/components/services, visibility, access to MQTT etc. etc.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @overfl0w said in qt.qpa.xcb: could not connect to display:

      which is still ROOT privilege uid/gid of 0), it fails about the 3rd of 4th plugin loading (XCB)

      Usually, root cannot access X server when running from other user account. Do you really have to start your app as root?

      Regarding plug-ins: set QT_DEBUG_PLUGINS=1 in a terminal and start your app there: there should be much more output providing more details why exactly the plug-in isn't loaded, please post it.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2

      • Login

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