在容器启动挂载了X11服务,然后在容器终端运行rviz、rqt等出现打不开界面情况:
root@846616f4a570:/# rviz2
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
若第一行display后面没有跟数字(就像上面显示),需要自己设置环境变量:
1.在宿主机查看用的端口
echo $DISPLAY
若输出为 :1
2.在容器终端设置相应的环境变量
export DISPLAY=:1
3.最后在宿主机打开xhost
xhost +
4.启动rviz2、rqt_graph等