Qt 应用程序无法初始化 WSL2 中的 XCB 插件

问题描述 投票:0回答:1

我在 Windows 11 23H2 上使用 Ubuntu 20.04 LTS 设置了 WSL2 环境。以前,我可以毫无问题地运行 Qt5 应用程序。然而,我在另一个程序中遇到了对Qt4的要求,这导致我卸载Qt5并安装Qt4。满足该要求并重新安装 Qt5 后,我开始在启动 Qt5 应用程序时遇到问题。

我收到的错误消息如下:

qt.qpa.xcb: could not connect to display 127.0.0.42:0
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.

我尝试根据 /etc/resolv.conf 文件中找到的 IP 地址设置 DISPLAY 环境变量,如下所示:

host_ip=$(cat /etc/resolv.conf | grep -o -E "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}")
export DISPLAY=$host_ip:0

有没有人遇到过类似的情况,或者有人可以指导如何在 Qt 版本之间切换后在 WSL2 中正确配置运行 Qt5 应用程序的环境吗?

linux qt wsl-2 xcb
1个回答
0
投票

我不知道 WSL 的早期版本需要手动配置 X11,但随着版本的更新,此功能已嵌入到 WSL 中。我昨天更新了WSL版本,这就是我遇到这个问题的原因。解决办法就是把DISPLAY相关的内容去掉

host_ip=$(cat /etc/resolv.conf | grep -o -E "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}")
export DISPLAY=$host_ip:0

来自我的 .bashrc 文件。

© www.soinside.com 2019 - 2024. All rights reserved.