Wayland环境QT应用

树莓派Raspberry Pi 400 上安装 Raspberry Pi OS for ARM 64系统,为了精简系统,采用 wayland显示服务器协议 图形服务上运行的 sway - i3兼容Wayland compositor ,对应用有特定运行配置要求:

在运行QT5应用时,例如 小企鹅输入法fcitx 配置工具 fcitx5-config-qt 启动报错:

qt.qpa.xcb: could not connect to display :0
zsh: segmentation fault  fcitx5-config-qt

解决方法是需要向QT应用传递环境变量 QT_QPA_PLATFORM=wayland ,所以修改 /etc/environment

QT_QPA_PLATFORM=wayland

然后再次运行QT应用就正常

我在 MacBook Air上运行Arch Linux 上部署 archlinux Sway图形桌面 ,运行 keepassxc 程序,再次遇到类似报错:

在 Wayland 环境运行Qt程序报错,显示无法找到Qt平台插件"wayland"
qt.qpa.plugin: Could not find the Qt platform plugin "wayland" in ""
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.

Aborted (core dumped)

此时,在 $HOME/.bashrc 中添加如下 QT_QPA_PLATFORM 环境变量:

添加 QT_QPA_PLATFORM 环境变量
export QT_QPA_PLATFORM=wayland

报错信息有所减少,但是依然显示没有platform plugin:

设置 QT_QPA_PLATFORM 环境变量后依然报没有找到Qt平台插件"wayland"
qt.qpa.plugin: Could not find the Qt platform plugin "wayland" in ""
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.

Aborted (core dumped)

不过,可以看到 xcb 连接错误消失了,情况有改善,但是还是说明应用程序以来的 QT wayland 没有安装。那么是哪个软件包呢?

检查当前系统已经安装的QT相关软件包:

检查系统已经安装了那些QT包
pacman -Q | grep qt

输出如下:

检查系统已经安装的QT包,可以看到只有 qt6-wayland 但是没有 qt5-wayland
fcitx5-qt 5.1.6-6
qt5-base 5.15.15+kde+r127-1
qt5-svg 5.15.15+kde+r5-1
qt5-translations 5.15.15-1
qt5-x11extras 5.15.15-1
qt6-base 6.7.3-2
qt6-declarative 6.7.3-3
qt6-translations 6.7.3-1
qt6-wayland 6.7.3-1
  • 则尝试安装 qt5-wayland :

安装 qt5-wayland
pacman -S qt5-wayland

果然,安装了 qt5-wayland 补齐了 KeePassXC 运行依赖,就能够正常运行

参考