Solve the problem of qt.qpa.xcb: could not connect to display

2022/07/21 update

Now WSL2 can run Linux GUI directly! ! ! No need to install Xserver (XLaunch) or the like anymore! ! !
Refer to Microsoft's official tutorial: Running Linux GUI Applications on the Windows Subsystem for Linux

However, it is worth noting that :
if you have previously .bashrcset the display command for Xserver in , you need to cancel it! Right now:

#export DISPLAY=xxx.xx.x.xx:0.0
#export LIBGL_ALWAYS_INDIRECT=
#export LIBGL_ALWASY_SOFTWARE=1

Otherwise, if you follow the official Microsoft tutorial, you will find that geditthe program will not respond when you run it! ! !


problem background


System: Ros system is installed on Ubuntu 20.04 in the Microsoft subsystem WSL . In order to run graphical programs on WSL, Xserver is installed. An error occurred when testing ROS
. The main reason is to refer to this article

Problem Description

When running the command referring to the previous article rosrun turtlesim turtlesim_node, an error occurred:

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:...

solution

The reason for this problem is that the ROS program cannot connect to the graphical interface. The problem lies in this code:

export DISPLAY=:0.0
export LIBGL_ALWAYS_INDIRECT=
export LIBGL_ALWASY_SOFTWARE=1

There export DISPLAY=:0.0is a problem with this sentence (maybe the author has no problem running it, but I will report an error when running it on my computer), here you need to add your own WSL IP address, the way to check the WSL IP is to open the command line ( ), cmdenter ipconfig
It will display insert image description here
In other words, it needs to be written as export DISPLAY=xxx.xx.xx.xx(IP):0.0
In addition, :0.0it needs to be consistent with the Display Number set by XLaunch. The default is -1, which is equal to 0.
If it is set to other numbers, such as 1, the above settings need to be changed In export DISPLAY=xxx.xx.xx.xx(IP):1.0
insert image description here
addition, the third item in the figure below needs to be checked
insert image description here

reference

[1] WSL (Ubuntu 18.04 LTS) installs ROS and can run Rviz and Gazebo

Guess you like

Origin blog.csdn.net/hypc9709/article/details/124238176