1. 错误代码
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, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl, xcb.
2. 原因
# 在VsCode的终端运行
$ env | grep DISPLAY
# 没有任何结果
VsCode上的终端是远程登录的,此时终端env没有DISPLAY这个变量,而DISPLAY用来设置将图形显示到何处,所以导致插件“xcb”无法加载
3. 解决办法
# 在系统终端上查看DISPLAY
$ env | grep DISPLAY # 获取屏幕
DISPLAY=:1
# 在VSCode的终端上设置DISPLAY
$ export DISPLAY=:1
# 执行上面的命令,将导致designer无法输入中文
# 解决办法
# 在系统终端上,切换到qt5虚拟环境,再执行 designer
# 此时可以输入中文