在Win11的Ubuntu22.04中运行ROS2 Humble turtlesim遇xcb显示错误求助
问题解决:WSL2 Ubuntu中ROS2 Humble运行turtlesim_node出现Qt xcb错误
错误信息
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: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.
解决步骤
安装Windows端X服务器
下载VcXsrv或Xming,启动时务必勾选「Disable access control」选项,确保WSL能连接到X服务器。配置WSL的DISPLAY环境变量
- 临时生效:在终端执行以下命令
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0 - 永久生效:编辑
~/.bashrc(使用zsh则编辑~/.zshrc),将上述命令添加到文件末尾,执行source ~/.bashrc使配置生效。
- 临时生效:在终端执行以下命令
安装缺失的Qt xcb依赖库
在WSL终端执行:sudo apt update && sudo apt install libxcb-xinerama0 libxcb-cursor0验证运行
重启终端后,重新执行ros2 run turtlesim turtlesim_node,turtlesim窗口应正常弹出。
内容的提问来源于stack exchange,提问作者PlaidTrack
相关产品推荐
相关产品推荐

